Web Application Projects and Web Site Projects in Visual Studio

We can create two different types of ASP.NET projects; the web application project and the web site project. In this article we will discuss the differences and some of the uses of the web application and web site project types.

When creating a new ASP.NET project, we have two options, Web Site projects and Web Application projects. Though selecting either of the project types doesn't have any impact on the application's performance and functionality, there are a few differences between the two. Since once we have create a web application project or a web site project some effort is required to convert from one type to the other type later on, since there is no direct way to convert between them. So it is useful to understand the differences between the two.

Visual-Studio1.jpg

ASP.NET Template for creating Web Application Project

Visual-Studio2.jpg

ASP.NET Template for creating Web Site Project

Here are some of the differences between the two.

Project file structure differences: In the case of web application projects a project file (.csproj or .vbproj) contains the project related information such as the list of files in the project. In the case of web site projects there is no project file and all of the files in all the folders are part of the application. Not using the project file has certain advantages, such as we can easily add or remove files from the project without using Visual Studio (directly copying the files). So if the requirement is that you should  be able to add or remove files without using Visual Studio then using web site projects is a good option.

In the case of web application projects we can easily exclude any of the files from the project without deleting it. This is not possible in the case of web site projects.

Web Application Projects have a project file.

Visual-Studio3.jpg

Compilation Differences: We explicitly compile the web application project on the machine used for developing the application, and all the code behind files and the class files are compiled into a single assembly. Web site projects are dynamically compiled into multiple assemblies upon the first request.

Deployment  Differences: We deploy the assemblies to the server for web applications while we copy the source code files to the server in the case of web site projects. Web site projects are more suitable when we want to directly update the source code on the server after deployment. We can deploy the updated assemblies instead of recompiling the entire site in the case of web site projects.

If we have multiple projects in the application and  want to establish dependencies among them then the web application projects are more suitable. Also if we do not want to expose our source code on the production server then web application projects are the correct option.

Note that some types of features work only with web application projects such as ASP.NET MVC and Edit and Continue feature of Visual Studio. Also if we want to run unit tests for classes other then the code behind classes then we should select the web application project type.