ASP.NET MVC File and Folder Structure
In this article, I am going to discuss the auto-generated ASP.NET MVC File and File Structure when we create a new ASP.NET MVC application. Please read our previous article before proceeding to this article where we discussed How to Create ASP.NET MVC 5 Application step by step from scratch.
Nowadays, the ASP.NET MVC framework becomes more popular among developers because of the separation of concerns (codes) and folder structure. As a developer, it is very important for you to understand the need and use of each file and folder of an ASP.NET MVC application. When we create an ASP.NET MVC 5 application, Visual Studio by default creates the following files and for our application.
Let us discuss the need and use of each File and Folder in detail one by one.
The App_Data folder of an ASP.NET MVC application contains application-related data files like .mdf files, LocalDB, XML files, etc. The most important point that you need to remember is IIS is never going to serve files from this App_Data folder. In our example, this folder is empty as we don’t have any data files. In our upcoming articles, we will discuss how to store application-related data files in App_Data Folder.
The App_Start folder of an ASP.NET MVC application contains configuration-related class files which are needed to be executed at the time of application starts. The classes like BundleConfig, FilterConfig, RouteConfig, IdentityConfig, etc are stored within this folder. We will discuss the use of each of these class files in detail in our upcoming articles.
The Content Folder of an ASP.NET MVC application contains static files such as image files, CSS files, icons files, etc. When we create a new ASP.NET MVC 5 application, then by default bootstrap.css, Site.css, and bootstrap.min.css files are included by Visual Studio as shown in the image below.
The Controllers Folder of an ASP.NET MVC application contains all the controllers of your application. The Controllers are nothing but classes that are inherited from the base Controller class. The name of the Controller should end with the word “Controller”. It is this class that actually handles the user’s request i.e. the incoming HTTP Requests and returns a response. In our upcoming articles, we will discuss the controllers in detail.
The Fonts folder of an ASP.NET MVC application contains the custom font files that are required for the application.
The Models folder of an ASP.NET MVC application contains the class files which are used to store the domain data (you can also say business data) as well as business logic to manage the data. In our example, the Models folder is empty as we have not created any models for our application. In our upcoming articles, we will discuss Models in detail.
The Views Folder of an ASP.NET MVC application contains all the “.cshtml” files of your application. In MVC, the .cshtml file is a file where we need to write the HTML code along with the C# code. The Views folder also includes separate folders for each and every controller for your application. For example, all the .cshtml files of the HomeController will be in the View => Home folder. We also have the Shared folder under the Views folder. The Shared Folder contains all the views which are needed to be shared by different controllers e.g. error files, layout files, etc.
Now, let us discuss the configuration files which are created by the framework by default:
The Global.asax file in an ASP.NET MVC application allows us to write the code that we want to run at the application level or you can say global level, such as Application_BeginRequest, Application_Error, Application_Start, Session_Start, Session_End, etc. In our upcoming articles, we will discuss the use of these application-level events in detail.
The Packages.config file in an ASP.NET MVC application is managed by NuGet Package Manager which will keep track of what packages and versions have been installed in your application.
The Web.config file of an ASP.NET MVC application is one of the most useful and important files which contains the application-level configurations such as connection strings, global variables, etc.
Here in this article, we discussed the ASP.NET MVC File and Folder structure. Once you understand the need and use of each folder and file of an MVC application, then it is easy for you to find, store and organize project-related files.
In the next article, we are going to discuss Controllers in ASP.NET MVC Applications. Here, in this article, I try to explain the need and use of ASP.NET MVC File and Folder structure which are auto-generated by Visual Studio. I hope this article will help you with your needs.
About the Author: Pranaya Rout
Pranaya Rout has published more than 3,000 articles in his 11-year career. Pranaya Rout has very good experience with Microsoft Technologies, Including C#, VB, ASP.NET MVC, ASP.NET Web API, EF, EF Core, ADO.NET, LINQ, SQL Server, MYSQL, Oracle, ASP.NET Core, Cloud Computing, Microservices, Design Patterns and still learning new technologies.