This post is just an introductory post on the ASP.NET Core application. In this post, we’ll create an ASP.NET Core application and we’ll examine the folders and code.
If you miss my previous post on ASP.NET Core and Benefits. Take a look.
To run/create applications for .NET Core we need the following things
- Visual Studio 2017
- .NET Core 2.1 SDK (for the purpose of this article only).
- Make sure Visual Studio 2017 has the “cross-platform development” workload is installed through visual studio installer
Creating our application:
For creating .NET Core applications open the Visual Studio 2017 and select
Project. And this should launch the Templates wizard like this.
Select as highlighted in the below screenshot.
ASP.NET Core Web application template holds several other templates. Select the appropriate template and framework and hit
Now, this should create our application. Notice that we also have templates for Angular, React and Redux in the above screen.
Let’s run the application. Press
Ctrl + F5.
There it is. Our application is up and running.
Let’s examine the folder structure now. Here is what our solution looks like
As you can see we also have wwwroot folder along with MVC structure. The wwwroot folder will have static files such as CSS, JS, HTML, images. This is called as Web root.
To access these files, the URI format is
Let’s try to access one image.
Here is the screenshot of the code
This is just having a Main method to run the app with the default host builder. Notice we have a CreateWebHostBuilder property.
WebHost.CreateDefaultBuilder method sets the content root to the current directory.
Program.cs also sets the startup using
Let’s see what we have in the Startup.cs class
ConfigureServices method is called by the runtime as indicated in the comments above the method. This method can be used to add services.
There are several other options to add into this Configure services method.
This method is used to configure what the application needs.
Notice the configure method here, we have the following statement
This is responsible for serving the static files in our application.
If we comment that out, we cannot access the static resources anymore. We’ll see all our images, js and CSS will be stopped and our application looks like this.
Things like SignalR, Routing, Third party authentication can be configured here. That’s about the Startup file.
This JSON file is to configure holds the configurations to run the application.
As we are running the application on IIS Express, the necessary configuration for IIS Express is utilized.
In the above JSON, we have applicationUrl:
http://localhost:51681 and a sslPort: 44307 is allocated. So, 44307 is for SSL port meaning this is for accessing the site with HTTPS://. So https://localhost:44307 is secured while http://localhost:51681 is just a plain HTTP which is not secured.
So, HTTP and HTTPS are configured by default.
The other folders like Controllers, Models, Views are with the any other MVC projects we have encountered before. Not found anything special in those files
Thanks for reading.
Subscribe to Code Rethinked
Get the latest posts delivered right to your inbox