ASP.NET MVC folder structure
Published: 2024-07-11 06:32:56

When our project created let's see what we got inside the project. So open up Solution Explorer here we got the bunch of folders as below :-

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i9bic4hxpv26tf2skoeq.png)

**App_Data :-**
It is where our database file is stored. 

**App_Start :-**
It includes few classes like BundleConfig.cs, FilterConfig.cs, IdentityConfig.cs, RouteConfig.cs, Startup.Auth.cs that are called when the application is started.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gp56twmw3tlv7asp954q.png)

**RouteConfig.cs :- **
This file consists the configuration about routing rules. Here we see the route with the name "Default" and has a URL pattern. So if a URL matches this pattern, the first part of the URL is assumed to be the name of the controller, the second part is assumed to be the name of the action and the third part is an id which can pass to the action. We can see we have some default values in this route. So, if a URL doesn't have any of this parts it will be passed to the "Home" controller. Similarly if the URL has only the controller but not the action it will be handled by the "Index" action. Also we can see that id is an optional parameter because not the every action needs an id we all need this when we are working with the specific resource like a movie or a customer with the given id.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vftssvt3kr7wmrlw7pqi.png)

**Content :-**
Here we store the CSS files, images and any other client side assets.
 
**Controller :-**
Our default project template has three controllers. "Account" which has actions for Sign up, login, log out. "Home" which present the home page and manage to provide for handling requests around users profile like changing password, enabling two factor authentication, using social logins and so on. 

**Fonts :-**
We have fonts which should not be here in the root. I will personally prefer to move this under content folder.

**Models :-**
We have Models so all are domain classes will be here.

**Scripts :-**
Where we store our JavaScript file.

**Views :-**
In Views folder, we have folders named same as controllers in our applications. So by convention, when we use a view in a controller ASP.NET MVC will look for that view in the folder with the same name as the controller.

**Shared :-**
 This includes views that can be used across different controllers.

**favicon.ico :-**
favicon is the icon of the application displayed in the browser.
 
**Global.asax :-**
This is one that has been in ASP.NET for a long time and it is a class that provides hooks for various events in the application life cycle. So let's expand this open the C# file (Gloabal.asax.cs) so when the application is started, the method Application_Start() is called. And here we can see we are registering a few things like the Routes. So when the application started we tell the runtime these are routes for application.

**Packages.config :-**
This is used by the NuGet package manager. If we have never heard for NuGet. It is a package manager similar to NPM (Node package manager) or Bower. If you never heard for any package manager before, we use them to manage the dependencies of our applications. So let's say our application has dependency to five external libraries. Instead of going to five different websites for downloading this libraries, it is more easy to use package manager because the package manager and this NuGet package manager will download these dependencies from its central repository. Also if in the future one of these libraries has a newer version. Again we use our package manager to upgrade one or more of the existing packages. We don't have to go to the five different websites.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bas4x20enlbhj07v52km.png)

**Startup.cs :- **
This is a new approach Microsoft is taking for starting the application. So the next version of ASP.NET called ASP.NET CORE 1.0, they have dropped the global.asax and all the startup logic is implemented in this Startup class.

**Web.config :-**
This is a XML that includes the configuration for the application. Out of all the elements we see in this XML, mostly we only to work with only two sections. "connectionStrings" which is where we specify the database connection string and "appSettings" which is where we define configuration settings for application.