TheDeveloperBlog.com

Home | Contact Us

CSharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript

ASP.NET HTTP Pipeline

This ASP.NET article examines the pipeline. It shows how files are handled based on their types.

IIS handles files based on their types.

You are doing ASP.NET development on virtual/shared hosting. You need pointers on how you can make IIS 7 work well with an ASP.NET application.

Introduction. We see how IIS 7 works in conjunction with ASP.NET to serve files. This is often confusing. Both IIS and ASP.NET work in the same pipeline.

Some files are mapped to ASP.NET. The administrators of your server will have mapped some files to ASP.NET. When a request is for any .aspx file, ASP.NET takes over.

Static files handled separately. Shared hosts like Go Daddy will map static files (HTML, GIF, CSS) to the IIS server. ASP.NET will not run or receive these requests.

Global.asax only runs with ASP.NET. Files that are served from IIS do not go through Begin_Request in ASP.NET. This means that ASP.NET is oblivious to those files.

Note: All of these settings can be manually changed. But these are how things are with many shared ASP.NET hosts.

Extensions mapped to ASP.NET include *.aspx and *.ashx. And extensions mapped to IIS 7 include *, *.gif, static web page file extensions, and directories.

Global.asax. On a setup where only asax files are processed by ASP.NET, handle only *.aspx files in Global.asax. Other requests will never come through Begin_Request.

The default ASP.NET development server in Visual Studio acts differently than shared hosts. Your site will handle errors differently locally than remotely.

Directories are handled separately still. When IIS receives a request for a directory, it will handle that request if the directory exists.

However: If the directory isn't there, then it will send the request to ASP.NET.

And: This means that ASP.NET cannot intercept a request for a directory that exists.

A pipeline optimization. HTTP modules slow an ASP.NET application's pipeline. They can be removed. Microsoft's documentation states that you can save memory and CPU cycles in this way.

To continue, many HTTP Modules are not necessary for most sites. Many ASP.NET applications do not use AJAX, probably the large majority.

And: ScriptModule, which is included by default in ASP.NET web sites, is for AJAX.

Tip: To remove it, open Web.config and scroll down to where you see the following section, and delete it.

Web.config fragment: XML

<httpModules>
    <add name="ScriptModule"
	 type="System.Web.Handlers.ScriptModule ...
</httpModules>

Next, add these entries to the httpModules section using simple XML comments. You can also comment out <httpHandlers>, as well as the section at the bottom called <system.webServer>.

Web.config fragment 2: XML

<httpModules>
    <remove name="OutputCache"/>
    <remove name="Session"/>
    <remove name="WindowsAuthentication"/>
    <remove name="FormsAuthentication"/>
    <remove name="PassportAuthentication"/>
    <remove name="RoleManager"/>
    <remove name="UrlAuthorization"/>
    <remove name="FileAuthorization"/>
    <remove name="AnonymousIdentification"/>
    <remove name="Profile"/>
    <remove name="ErrorHandlerModule"/>
    <remove name="ServiceModel"/>
</httpModules>

Now, run your project in Visual Studio's debugger and the ASP.NET development web server. If you are not using any of the required modules, your site will be slightly faster.

Note: Few ASP.NET sites use all of these modules, so most sites can probably benefit from this optimization.

Note 2: I verified in the Visual Studio debugger that the string array containing the HttpModule list was reduced to 1 from 10.

String Array

Research. The document at Microsoft is called "Performance Tips and Tricks in .NET Applications." Halfway through, it offers some useful tips regarding ASP.NET.

Note: The document specifically notes that this is not a big gain. So other changes too will be needed.

Depending on the features used, remove unused or unnecessary http modules from the pipeline. Reclaiming the added memory and wasted cycles can provide you with a small speed boost.

Performance Tips and Tricks: MSDN

Concepts. We looked at some concepts related to HTTP pipeline handling in ASP.NET. Inconsistencies exist between file mapping and handling on different ASP.NET hosts.

The platform uses a pipeline model, where the software tries to handle each request first by IIS and then by ASP.NET if specified. ASP.NET doesn't handle all file types.