#04 First ASP NET Core project | Introduction to ASP.NET Core | ASP.NET Core MVC Course

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
now that we have Visual Studio installed on our development machine let's go ahead and let's create our very first asp.net core project let's go to visual studio and to create a new project let's click on this button create a new project it will take us to the project template page so here you can see a lot of templates for creating different types of projects for example creating a console application or a Blazer server application asp.net core web API class Library Etc so here we have lot of different types of templates now we want to filter these templates based on the language as C sharp and the project type is web okay so now these templates which you are seeing here they use C sharp as the programming language and they are basically the web templates now here we want to create an asp.net core application for that we have two templates here asp.net go web app and asp.netco empty so we can choose any one of these two templates if we choose this first template this asp.net go web app in that case it is going to create a project for us and in that project we are going to have some Auto generated files and folders but if we choose asp.net core empty in that case it is going to create an empty asp.net core project so for learning purposes this is the one which I am going to choose here using this template I can show you from scratch how asp.net go web application works okay so I'm going to choose asp.netco empty template here let's click on this next button now from here we can specify the name for the project I am going to call it maybe my first app then here we can specify the location where we want to store this project so here it has used the default location but let's say I want to store this project in C drive and in there I want to have this ASP net go folder so inside this asp.net core folder I want to store all my asp.net core related projects then here we can also provide a solution name so by default the solution name is same as the project name but if you want you can also change your solution name but I am going to keep it as it is finally we have this checkbox now if you check this checkbox in that case what will happen is the project file that means the dot CS project file and the solution file they will be placed in the same directory but if you don't check this in that case they will be placed in the separate directories solution file will be placed in the solution directory and the project file will be placed in the project directory okay so I am going to keep this unchecked and now let's click on this next button now from here we can select the dotnet framework which we want to use so if you remember during the installation we installed dot net 6.0 and Dot net 7.0 so here you can choose any one of them I'm going to choose the latest one which is dot net 7.0 and I don't want to configure https for now as I said I want to show you everything from scratch so I want to keep things as simple as possible so I am going to uncheck this checkbox and we also don't want to enable Docker so I will keep this checkboxes unchecked and now let's go ahead and let's click on this create button so it is going to create an empty asp.net core project for us so as you can see the project has been created let's close this overview tab all right so here my first app project has been created this is an asp.net core project and if you see in this project we have only one file which is this program.cs file now the very important point to keep in mind here is that asp.net go web application is actually a console project which starts executing from this program.cs file okay so when we run this asp.net core project the first file which gets executed is this program.cs file let's go into this program.cs file now in this program.cs file we have only four lines of code and if you notice these codes are not present inside a class or a method basically in a program.cs file we have a program class and inside that program class we have a main method and that main method is the entry point of any application but here in this program.cs file we don't have a program class and we don't have a main method as well basically from C sharp 9 what Microsoft has done is it has removed the program class and the main method so whatever code you write here inside this program.cs file it is similar to writing this code inside the static void main method of the program class okay so you can think of this code as the content of the static void main method of the program class so whenever the asp.net core project will run first it is going to execute these four lines of code now let's try to understand what these four lines of code are doing so the first line of code here it is going to create an instance of web application Builder so here we have this web application static class and on that static class we are calling this create Builder method and to that create Builder method we can pass some arguments now when we call this create Builder method it is going to return us an instance of web application Builder so let me put that comment here now what does this web application Builder do well the web application Builder pre-configures some defaults like configuration environment Services Etc on the web application now if this does not make any sense right now then don't worry we are going to talk about it in great detail in the future lectures of this course in this very first lecture let's try to keep things simple just understand that this first line of code creates an instance of web application buildup now on that web application Builder so basically we are storing that instance of web application Builder inside this build a reference variable so on that instance when we are calling this build method it is going to return us an instance of web application okay so at this line we are going to receive an instance of web application and it is this web application which is your asp.net go web application okay so here this app is going to store your asp.net go web application again I want to keep things simple here so I don't want to go into details but just keep in mind that this app is your asp.net go web application now in the next line we are creating a route on that web application okay so here we are creating a single route now what this line of code will do here we are basically creating a route for HTTP get method and the URL here is the root URL so this slash means root URL that means whenever a user will make a get request to the root URL this callback function will be executed and when this callback function will be executed this callback function is going to return this string in the response again if you don't know what a route is don't worry we are going to talk about routes in great detail in the future lectures for now just understand that a route is basically a URL and this route consists of HTTP method plus the URL okay so a route consists of HTTP method and the URL here URL is the root URL so this slash means root URL root URL is basically your domain name now when you are working in development there the root URL is your Local Host colon the port number on which your application is running okay and HTTP method is basically get post put delete Etc and we are going to talk about these HTTP methods again in the future lectures so here basically what we are trying to say is whenever a user makes a get request to the root URL in the response send him this string okay basically whenever a get request will be made to this URL this callback function will be executed this callback function will be called and when this callback function will be called it is going to return this string in the response and finally at this line we are starting the server okay so first we are creating an instance of web application Builder using that web application Builder we are creating an instance of web application and that web application is our asp.net core web application on that web application we are creating a route here we are creating a single route and then we are running this server so basically we are running that app on the server so if I go ahead and if I run this program here you can see the browser has opened so basically our application is running at localhost and port number 5136 so this is our root URL okay and when we have made a get request to this root URL in the response we have received this string hello world okay so localhost colon this port number is the root URL in our case and we are specifying that root URL in the code using this single slash okay so whenever a user makes a get request to this slash we are sending this string in the response hello world but instead of sending this string in the response let's send some other string so here let's say this is my first asp.net core app okay let's save the changes let's go to the browser and let's refresh the page so when I refresh the page I am still seeing the same response so the response is not updating here for that what I need to do is first I need to stop this application and then run it again or what we can also do is we can use this option called hot reload so let me click on this okay so here you can see down it is saying applying changes now if I go back to browser and if I refresh the page now you can see that we have that string in the response which we have just specified so it is this string which we are now sending in the response all right and you will also notice that in the background this console application is running and keep in mind that as long as this console application is running in the background your server is up and running as soon as you close this console application your server will also shut down okay so here in the browser I am getting this response from the server basically from our asp.net core app because this server is still running if I go ahead and if I close this that means we have shut down the server you will notice that the application has also stopped and now if I go ahead if I open the browser and there if I type that URL if I press enter you see we are not receiving any response it says the site can't be reached that's because we have closed the server now to again restart the server we can again run this application so when we run this application in the background this console application will start and as long as this console application will run this server will be up and running okay now here this server is starting because of this line of code this app dot run if I go ahead and if I comment this line of code we learned that using this run method we are actually starting the server right so if I go ahead and if I comment this code let me first stop this application and let me comment this code okay and now if I try to run this application you see it is not starting that's because it is not able to start the server so if I open that console app you see here also we have that message exited with code 0. so as I have mentioned before the asp.net Co web application which we create that is actually a console application so it is that console okay when we run this program file it is going to open this console application now when we uncomment this code it is going to start the server and we will see that log message in this console okay so let me close this console here and now let me start the application again so here we can see the response in the browser if we go to that console application here we can see some log information so for example we are listening on this localhost colon 5136 port number then the hosting environment is development environment and also the root path is this path okay so it is this console application which starts when this program.cs file gets executed let's stop the application here okay so keep in mind that asp.net core application is basically a console application when that console application starts internally it starts a server and on that server it hosts our asp.netco web application and this app is our asp.net go web application so basically this app gets hosted on that server when we use app.run so this app.run starts the server and on that server it hosts that web application all right so this is all from this lecture if you have any other questions then feel free to ask it thank you for listening and have a great day
Info
Channel: procademy
Views: 3,447
Rating: undefined out of 5
Keywords: asp.net core, first project, asp.net core tutorial, asp.net core 6.0, complete asp.net core mvc course
Id: nuh-MxHLIB0
Channel Id: undefined
Length: 14min 34sec (874 seconds)
Published: Sun Jan 08 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.