ASP.NET Web Site vs Web Application

ASP.NET Web Site vs Web Application

In Visual Studio .NET 2003 a "Web Project" model existed for web development. This was replace by a "Web Site" model in Visual Studio .NET 2005. Some developers found it was impractical to migrate from the "Web Project" model to the "Web Site" model. So Microsoft developed a "Web Application" project add-in for Visual Studio .NET 2005. The "Web Application" project worked like the original "Web Project". Since that time Microsoft has offered both the "Web Site" and "Web Application" models for web development.

Microsoft's distinction between a "web site project" (WSP) and a "web application project" (WAP) is a matter of the project's structure. Both types of projects have the same ability to process data and roughly the same performance. A WAP has a structure based on project files and a build model where all code in the project is compiled into a single assembly. A WSP uses a folder to contain all the related code and all the source code resides on the server. With a WSP, the source code is compiled before each request. With a WAP, a change to a program requires recompiling the project and deploying the resulting .dll's. While with a WSP the change could be made by simply moving the modified source code to the server.

Below are solutions for both a WSP (on left) and a WAP (on right) created with Visual Studio 2013. Notice the App_Code folder was created for the WSP, but not for the WAP. The App_Code folder is a special runtime folder which compiles any code it contains when the site is running. Adding something to the App_Code folder on a running website will cause the site to reset because the runtime will recognize the new code needs to be run. WAPs do not contain an App_Code folder because all of its code is deployed as dll's.

,Web Site vs Web Application


Solutions for Web Site Project (left) and Web Application Project (right)

Microsoft offers the following advice when considering which type of web project to use:

"It’s best to choose the right type before you create a web project, because it can be time-consuming, difficult, and error-prone to convert from one type to the other."

"For new development, we recommend that you choose web application projects. This topic explains that web site projects have some advantages, but many developers who choose web site projects eventually find that the disadvantages outweigh any perceived advantages. In addition, as new ASP.NET features are developed, they won’t always be made available for web site projects."


Area

Web application projects

Web site projects

Project file structure

A Visual Studio project file (.csproj or .vbproj) stores information about the project, such as the list of files that are included in the project, and any project-to-project references.

There is no project file (.csproj or .vbproj). All the files in a folder structure are automatically included in the site.

Compilation

  • You explicitly compile the source code on the computer that is used for development or source control.

  • By default, compilation of code files (excluding .aspx and .ascx files) produces a single assembly.

  • The source code is typically compiled dynamically (automatically) by ASP.NET on the server the first time a request is received after the site has been installed or updated.

    You can precompile the site (compile in advance on a development computer or on the server).

  • By default, compilation produces multiple assemblies.

Namespaces

Explicit namespaces are added to pages, controls, and classes by default.

Explicit namespaces are not added to pages, controls, and classes by default, but you can add them manually.

Deployment

  • You copy the assembly to a server. The assembly is produced by compiling the application.

  • Visual Studio provides tools that integrate with Web Deploy (the IIS web deployment tool) to automate many deployment tasks.

  • You copy the application source files to a computer that has IIS installed on it.

  • If you precompile the site on a development computer, you copy the assemblies produced by compilation to the IIS server.

  • Visual Studio provides tools that integrate with Web Deploy (the IIS web deployment tool) to automate many deployment tasks.