What part of the ASP.Net framework do you use to execute arbitrary code on every inbound request to IIS?

StackOverflow https://stackoverflow.com/questions/650760

  •  19-08-2019
  •  | 
  •  

Question

I'd like to run a discrete chunk of .Net code for each and every request that comes through a certain Web site in IIS. This is completely isolated code -- it doesn't affect anything before or after it -- it logs some information from the request, then ends.

Note that this is not something I can put in Application_OnRequestBegin or some other ASP.Net file because I need this to execute for non .Net files (PDFs, images, etc.). It needs to execute for requests that would normally not hit the .Net framework.

Is an HTTP Module what I'm looking for? I've RTFM'ed quite a bit, but it seems there a number of different ways to manipulate the pipeline, and I'm not quite sure which one I should be using.

Was it helpful?

Solution

You can use an HTTP Module, however, to use it you will need to map all requests to IIS which can be done using a wild card map.. This will have a performance impact because you're going to be forcing all requests through the .net runtime.

You could also write your own ISAPI filter, but I believe you'll have to use C++.

Edit

ASP.Net has a default handler if your doign the wild card mapping you need, make sure you still have this in your web.config in your windows/microsoft.net/framework..../config/ folder:

<httpHandlers>
....
            <add path="*" verb="GET,HEAD,POST" type="System.Web.DefaultHttpHandler" validate="True"/>
</httpHandlers>

You might have also removed the handler in your web's config file. Lastly you could try and add an explicit mapping for the pdf file.

OTHER TIPS

You want to write an ISAPI filter (5.0 terminology), or extension (in 6.0).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top