我有一个简单的 HTTPModule,它执行一些自定义 session 状态管理。
public void Init(HttpApplication context)
{
context.AcquireRequestState += new EventHandler(ProcessBeginRequest);
ActivityLogger.LogInfo( DateTime.UtcNow.ToLongTimeString() + " In Init " + HttpContext.Current.Request.Url.AbsoluteUri);
}
和
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;
}
当我使用断点运行此代码时,我发现即使对于图像、js 和 css 等静态文件也会调用此模块。有人经历过这个吗?我认为 HTTP 模块仅连接到 asp.net 页面的 http 管道中的事件。它们是否也连接到静态资源?或者只是卡西尼号?
环境:VS2008-cassini服务器
PS:我确实在我们的沙箱(有点新)中使用Win2k8 IIS7尝试过,并尝试将其写入日志文件(因为我们那里没有VS),但无法写入日志文件。我确定它有一些写入权限问题。任何人都可以向我指出一些资源,告诉我如何在 W2k8 中使用 IIS7 运行 ASP.net 时设置目录的写入权限
Edit1:我知道使用集成管道会扩展静态和托管资源的http管道 https://web.archive.org/web/20210612113955/https://aspnet.4guysfromrolla.com/articles/122408-1.aspx和 http://learn.iis.net/page.aspx/243/aspnet-integration-with-iis7/
我们在我们的产品中使用经典管道。但仍然有兴趣了解其他人的经历。
问题2:在集成模式下使用IIS7,会降低性能吗?假设您有几个模块与管道连接,对性能的影响有多大?如果有人能给我指出为此所做的一些基线研究,那就太好了。
最佳答案
看来有办法做到这一点
http://learn.iis.net/page.aspx/121/iis-70-modules-overview/#Disabling
设置preCondition="managedHandler"
和<modules runAllManagedModulesForAllRequests="false" />
就可以了
self 提醒: http://code.google.com/p/talifun-web/wiki/StaticFileHandler 需要探索这个StaticFileHandler
引用文献:
http://learn.iis.net/page.aspx/244/how-to-take-advantage-of-the-iis7-integrated-pipeline/
关于asp.net - JS、图像和CSS被HTTPModule拦截,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2112728/