Need a simple CRM and Project Management system?
Check out JobNimbus - CRM for Contractors and Service Professionals.

Global.asax Events in IIS 6 and IIS 7 for Static Resources

A quick and easy way of doing URL rewriting or responding to requests for static resources is to use the Application_BeginRequest event. This event will fire each time a page is requested. In there, you could do something like the following to serve a different file when a specific URL is requested to your site:

// get the current URL
string sUrl = Request.Url.PathAndQuery;
if (sUrl == "/my-pretty-url/some-page")
    // rewrite the URL to a different path 
    // (NOTE: user's browser's address will stay the same)

You could also block access to a static resource like an image from being served based on some criteria. In this code sample, I’ve blocked access to an image if the caller is a specific website I don’t want to serve my images to:

// get the current URL
string sUrl = Request.Url.PathAndQuery;
// check the IP address of the caller
if (Request.UserHostAddress == "" && sUrl == "/images/my-image-name.png")
    // serve up 404 error because we don't want this client to get access 
    // to this image resource
    Response.Status = "404 Not Found";
    Response.StatusCode = 404;

These code samples will run great in your Visual Studio 2008 or 2010 Cassini built-in web server, but if you deploy them to a standard IIS 6 or IIS 7 server, you will be scratching your head because your Global.asax events will not fire when static resources are requested.

Problem in IIS 6

For IIS 6, the reason for this is that the IIS pipeline does not support native .NET IHttpModules. Pre-IIS 7, .NET was an ISAPI plug-in for IIS instead of native to the server. Static resources get served by IIS using the built-in IIS services. Therefore, static resources do not go through the ASP.NET pipeline and your events are not fired.

IIS 6 Solution

There are several solutions to get IIS 6 to run your Global.asax file events whenever a static resource is served. The easiest to implement is to add a wild card mapping to your server to run all requests through the .NET run-time. To do this, first right-click on your IIS web site instance that you want to change and choose properties.

Click on the Home Directory tab and then click "Configuration" next to your web application instance.

On the Wildcard application maps section, click "Insert" (NOTE: don’t click "Add")

Enter the path to your ASP.NET ISAPI dll. For instance, if you are using .NET 2.0, then your path would like this:


If you are using .NET 4.0, then it will have a similar path.
Make sure to NOT check the box "Verify that file exists" and then click OK.

There are other solutions as well but this one is simplest. On high performance, high traffic sites, you may want to consider alternatives because this solution could affect performance since all static resources will be served by ASP.NET instead of the native IIS server (which could be slower in some cases). Other solutions and more information this is in this great article here:

Problem in IIS 7

In IIS 7, the .NET pipeline is fully integrated into IIS but by default, IIS does not serve static resources through your ASP.NET application. So your events will not fire for these types of resources.

IIS 7 Solution

The easy solution in IIS 7 is to add a setting in your web.config file to tell IIS to process all requests through your Global.asax events. Just add or change this section in your web.config to enable requests:

  <modules runAllManagedModulesForAllRequests="true" />

Thanks for the data, perhaps

Thanks for the data, perhaps I will use this all over my tufted selling and i have been use much ring American statedia in run a interaction and that they somebody existing a giant amend on me. Judi Bola

Playground Tiles are utilized

Playground Tiles are utilized widely around the world; these tiles aren't only fashionable but provide safety for the floor. These tiles are simple to clean as well as sweep, many of the cleaner costs are preserved by these types of tiles. PLAYGROUND TILES

How about iis 5.1

I running on iis 5.1, window XP,

I do as your guilde but cannot. script in .asax file still ignored.

You should comment on the

You should comment on the competition comparison of the blog. You can highlight it's mind boggling. Your blog exploration/tour will broaden your conversions.

Thanks for the info, maybe I

Thanks for the info, maybe I can use this ended my tufted marketing and I've been use untold anulus media in run a interaction and they someone existing a big amend on me. Betting Predictions

Thanks so much with this

Thanks so much with this fantastic new web site. I’m very fired up to show it to anyone. It makes me so satisfied your vast understanding and wisdom have a new channel for trying into the world. Liga Inggris

Thank you

Hi friend,

your post was very useful to me. thank you very much..

Great! Thank you!


Thanks a lot for that!

redM Software, Marcel

IIS Solution 7 does not work

The IIS 7 solution is not working...


Simply Superb....!

Thanks it helped me a lot

Thanks it helped me a lot

You saved the day.

Holy Toledo!

< system.webServer >
< modules runAllManagedModulesForAllRequests="true" / >
< /system.webServer >


I've been dying trying to get an old IIS6 (5.1) setup to work with IIS7.

I'm gonna put some key words here so others might this in the future in the scenario I was looking.

I had to add a space after the left bracket and before the right bracket to get it to post.

< system.webServer >
< handlers >
< add name="MyName" path="*.myext" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" allowPathInfo="true" / >
< /handlers >
< /system.webServer >

From what I've read (take it with a grain of salt), resourceType="Unspecified" is the equivalent of Verify that file exists. However, I needed it and the content of this article to get my setup t work.

From what I've read (take it with a grain of salt), resourceType="Unspecified" is the equivalent of "Verify that file exists" (from IIS6 (5.1)). However, I needed it and the content of this article to get my setup t work.

To create a such kind of

To create a such kind of article is really amazing,I daily read your blogs and give my announcement for that here this article is too great and so entertaining.

How to raise events in Global.asax for static requests. Thats it

Thanks a lot for your post. I was looking around for this all day and finally found this :)