views:

92

answers:

2

I have installed an HttpModule into my web app that will handle all requests with a given file extension.

I want ASP.NET to handle all requests with the extension, regardless of whether there is an underlying file on disk. So, when I added the extension to the 'Application Extension Mappings', I unchecked the 'Verify that file exists' checkbox.

However, this just transfers the file check to ASP.NET rather IIS, so I just get a different error page when requesting URLs with the file extension.

Is there a way to preempt this ASP.NET file checking and intercept the requests?

+1  A: 

In the Global.asax you can handle the BeginRequest event.

protected void Application_BeginRequest(object sender, EventArgs e)
{

}

You will most likely want to modify the Reponse object to make sure you can give a custom page or redirect accordingly.

If you do not have a Global.asax in your project just go to Add New Item > Global Application Class

Banzor
I'll try and do that, although what I've done is registered an HttpModule, whose BeginRequest handler never gets called - I don't have a Global.asax.
mackenir
Global.asax is available in Web Application projects. If your project is an ASP.NET web site (not application), you could either add a global.asax or handle via OnError: http://msdn.microsoft.com/en-us/library/system.web.ui.templatecontrol.onerror.aspx
Jim Schubert
+1  A: 

You need to create an HttpHandler instead of an HttpModule. Add the HttpHanlder extension to your web config and then all requests to the server for that extension will be directed to your handler.

<httpHandlers>
    <add verb="*" path="*.ext" type="Domain.Model.MyHttpHandler" />
</httpHandlers>

The handler can then serve up whatever it wants. If it's an unknown filetype you will need to advise IIS of the type and that it is handled by ASP.NET.

Here is a nice quick start guide

WDuffy