ASP.NET Web Application Project

Visual Studio logo (Copyright Microsoft)

You know that Web Application projects in ASP.NET are best for large deployments, but are wondering about how they compare to Web Site projects in efficiency and layout. Here we compare the same project as a Web Application and as a Web Site project, looking into the code's internals and measuring sizes.

This ASP.NET article looks into Web Application projects in Visual Studio.

ASP.NET Web Application footprint

Web application:                 35.0 KB
Web site project (precompiled):  64.5 KB

Create Web Application

Note

First, we see some introductory material to clarify the article. To make a new Web Application project in Visual Studio, you can first click on the File menu and go to New Project. A dialog will appear.

Reading the dialog. In the New Project dialog, select ASP.NET Web Application. The description will read "A project for creating an application with a Web user interface (.NET Framework 3.5)". Type in the name of your Web Application.

Add Global.asax file

Here we see how the Global.asax file differs between Web Applications and Web Site projects. To add the Global.asax file in your Web Application, right click on the Solution root in the Solution Explorer, and select Add -> New Item -> Global Application class (with the gear). Instead of having the C# event handlers in Global.asax, you put them in Global.asax.cs.

Global.asax note

Programming tip

I discovered that in Web Site projects, the Global.asax code is put in a new class called global_asax. This class contains an extra static field called __initialized. On every instantiation of the class, the variable is checked. This likely has a tiny negative impact on every request. This is the global_asax constructor:

Global.asax [C#]

[DebuggerNonUserCode]
public global_asax()
{
    if (!__initialized)
    {
	__initialized = true;
    }
}

Compared to Web Application projects. In a Web Application project, there is no __initialized variable or global_asax class. The instructions are simpler when inspected in IL Disassembler.

IL Disassembler Tutorial

Binary size

DLL (Dynamic Link Library)

When you use the precompiled site options for your Web Site project, pages are compiled into several DLLs. When you have separate files, less code can be shared between the files. This results in a higher total size of deployment. Additionally, many DLLs are slower to read in than one.

My web project. What we see next here is the binary size of the deployed web project BIN folder for a deployed ASP.NET site. First, the stats for the Web Application are shown, and then the stats for the precompiled Web Site.

Web Application

Number of files in BIN: 1
Size of files:          35.0 KB

Web Site precompiled

Number of files in BIN: 10
Size of files:          65.9 KB
Number of DLLs:         5
Size of DLLs:           64.5 KB

What the numbers indicate. The BIN file for the Web Site contained nearly twice as much data and ten times more files. This is clearly less efficient for the footprint than the single DLL from the Web Application project. There we no inline-code pages.

Settings for the web project. Next here are the settings for the Web Site project that were compared to the Web Application. All projects are in Release mode with no debugging enabled.

Precompiled Site
Publish Web Site options used

[ ] Allow this precompiled site to be updatable
[X] Use fixed naming and single page assemblies
[ ] Enable strong naming on precompiled assemblies

Reference sources

Other considerations may be more important to you than deployed binary size or startup efficiency. For more details, you should reference the MSDN article. It has much more detail.

MSDN reference

Summary

Here we looked at the first steps to create a Web Application project with a Global.asax file, and compared a real-world site as a Web Application project and as a Web Site precompiled project. Web Site projects result in many more binary files and some more complexity in Global.asax, which may impact negatively performance on high-volume sites.

ASP.NET Tutorials
.NET