ASP.NET Core Web Application Project Structure

Introduction :

In this post, we will learn about to ASP.NET Core and then I explain the project structure of an ASP.NET Core web application. If you are new to .NET Core, you can read my Introduction to .NET Core post first.

Also will Learn what changes have been made in ASP.NET Core from the project structure point of view and we will slightly discuss the execution pattern of ASP.NET Core application in this article

ASP.NET Core Project Structure

The following is a default project structure when you Create an  ASP.NET Core application in Visual Studio 2019.

ASP.NET Core Web Application Project Structure

The above solution explorer displays project solution. We can change it to folder view by clicking Solution and Folders icon and selecting Folder View option.

(1) Connected Services :

This is the first node in your project’s structure and possibly the less-used one. It is intended to automate the multiple steps necessary to connect a project to an external service (like Azure Storage or Application Insights). Usually, it just adds necessary packages and gives you basic instructions on how to start using the service in your app.

Dependencies :

This element of your project structure contains all packets or other projects on which your project depends.

There are two main folders inside this node.

1)  Analyzers :

Analyzers help you make your code better, cleaner, error-free. Each analyzer checks that your code satisfies a list of rules incorporated in it. If any part of your code does not apply to one of the rules, you will see either a Warning or an Error while you build your project. analyzers work only at compile time and do not affect your resulting application.

2)  Frameworks :

This folder contains a list of frameworks your project depends on. This information is important if you publish your web app as a runtime-dependent (as opposed to a self-contained one). In this case, all the frameworks listed here must be installed on the server where you will run your app.

(2) Properties :

This part contains different properties of your project that you can modify by double-clicking on this node in the Solution Explorer. Most of the properties there affect the compile- and debug-time behavior of your project.

The only item inside this node is a “launchSettings.json” file that contains the list of the launch profiles. Each profile defines how to run your project when you click on the “Run” button in Visual Studio. The following is a default launchSettings.json file

Asp.Net Core Properties

(3) wwwroot :

This folder contains all the static files of your web application: CSS files, JavaScript files, images, and icons. As you might figure out from its name, this will be the root folder of your web app.

Asp.Net Core wwwroot folder
(4) Pages :

This folder contains all pages (forms) of your web applications. ASP.NET Core has two default approaches for content rendering: MVC (Model View Controller) and Razor Pages (which is, actually, a kind of MVC, where each controller and the corresponding view are stored together). Both approaches use Razor syntax that you can think of as HTML + C#.

Asp.Net Core page folder

(5) Program.cs :

This file defines the “Program” class with one static method which is the entry point of your web application.The only purpose of this method is to define the host and then pass the control to the Startup class.

Asp.Net Core program file

 

(6) Startup.cs:

This class contains a lot of code from the very beginning and will become even bigger when you start adding new features to your application. The “Startup.cs” class serves three main purposes:

  1. It performs all initialization tasks (setting application-wide constants, DB seeding, migrations, etc.).
  2. It defines the middleware pipeline of your web-application.
  3. It registers all services used in this project in the dependency injection container.

Summary

In this tutorial, we have learned a few things about the ASP.NET Core Solution Structure or Project structure. The Visual Studio Team has made lots of improvements over the older system.

we will learn more about wwwroot folder in Asp.Net core in our next tutorial

SEE MORE ARTICLE

Leave a Reply

Your email address will not be published. Required fields are marked *