views:

379

answers:

2

I have a simple HTTPModule which does some custom session state management.

public void Init(HttpApplication context)
        {
            context.AcquireRequestState += new EventHandler(ProcessBeginRequest);
            ActivityLogger.LogInfo( DateTime.UtcNow.ToLongTimeString() + " In Init " + HttpContext.Current.Request.Url.AbsoluteUri);
        }

and

public void ProcessBeginRequest(object sender, EventArgs e)
        {
            HttpApplication application = sender as HttpApplication;
            ActivityLogger.LogInfo(DateTime.UtcNow.ToLongTimeString() + " In ProcessBeginRequest ");
            if (application != null)
            {
                string requestURL = application.Context.Request.Url.ToString();
                ActivityLogger.LogInfo(DateTime.UtcNow.ToLongTimeString() + " In ProcessBeginRequest " + requestURL);
            }
            return;
        }

When I ran this code with breakpoints, I saw that this module got invoked even for static files like images,js and css. Has anyone experienced this ? I am thinking HTTP modules were only hooking on to events in the http pipeline for asp.net pages . Do they also hook on to static resources ? Or is it just with cassini ?

Environment: VS2008 - cassini server

PS: I did try it with Win2k8 IIS7 in our sandbox (kinda new), and tried to write it to a log file (as we do not have VS there),but could not write to the log file. Am sure its some write permissions issue. Can anyone point me to some resource which tells me how to set write permissions for directories when running ASP.net with IIS7 in W2k8

Edit1: I understand that using Integrated pipeline would extend the http pipelines for static and managed resources alike http://aspnet.4guysfromrolla.com/articles/122408-1.aspx and http://learn.iis.net/page.aspx/243/aspnet-integration-with-iis7/

We are using classic pipeline in our prod. But still interested in knowing what other people have experienced.

Question2: Using IIS7 in integrated mode, will it decrease performance ? Say you have couple of modules hooking up with the pipeline, how much would be the performance impact? Would be nice if some one can point me to some baseline studies done for this.

A: 

Yes, it will be called for any type of files.

It's typical in those modules to filter out whatever you are not interested in for ex. by checking whether HttpContext.Request.Url.AbsolutePath contains '/_layouts' under SharePoint.

Ariel
Is there a way configure the modules such that they only get hooked up to the pipeline for specific extensions (like aspx or asmx or my custom ashx) ?
ram
This answer is specific for ASP.NET Development web server (Cassini) -- your question mentions IIS7 and Cassini. Cassini will route ALL requests to any HttpModules. Note this is different behavior than IIS6 or IIS7 (need different configuration to get the same behavior on each)
Adam
+2  A: 

Looks like there is a way to do it

http://learn.iis.net/page.aspx/121/iis-70-modules-overview/#Disabling

setting preCondition="managedHandler" and <modules runAllManagedModulesForAllRequests="false" /> would do the trick

note to self: http://code.google.com/p/talifun-web/wiki/StaticFileHandler need to explore this StaticFileHandler

references:

http://learn.iis.net/page.aspx/244/how-to-take-advantage-of-the-iis7-integrated-pipeline/

http://stackoverflow.com/questions/1156186/exclude-httpmodule-from-running-for-static-content-on-iis7

http://stackoverflow.com/questions/1267409/bug-iis7-managed-requests

http://msdn.microsoft.com/en-us/library/bya7fh0a.aspx

ram
thanks. added this to the todo for http://cassinidev.codeplex.com
Sky Sanders