JS,Images and CSS getting intercepted by HTTPModule

雨燕双飞 提交于 2019-11-29 15:09:48

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/2112728/js-images-and-css-getting-intercepted-by-httpmodule

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!