JS,Images and CSS getting intercepted by HTTPModule
Asked Answered
F

2

5

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 https://web.archive.org/web/20210612113955/https://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.

Fluoridate answered 21/1, 2010 at 20:42 Comment(0)
F
14

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/

Exclude HttpModule from running for static content on IIS7

BUG: IIS7 managed requests

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

Fluoridate answered 22/1, 2010 at 23:6 Comment(2)
Is there a nice way to achieve this in IIS6? I know it is slightly unrelated to the question, but would be a good reference for someone landing here, like me, because of the question title alone.Gujranwala
Did anyone make it to obtain caching with Talifun.Web StaticFileHandler?Eloquence
D
0

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.

Deadman answered 21/1, 2010 at 20:50 Comment(2)
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) ?Fluoridate
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)Shem

© 2022 - 2024 — McMap. All rights reserved.