代码之家  ›  专栏  ›  技术社区  ›  ram

HTTPModule截获JS、图像和CSS

  •  5
  • ram  · 技术社区  · 15 年前

    我有一个简单的HTTPModule,它执行一些自定义会话状态管理。

    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-卡西尼服务器

    PS:我确实在我们的沙盒中用Win2k8 IIS7尝试过(有点新),并尝试将其写入日志文件(因为我们没有VS),但无法写入日志文件。我确信这是一些写权限问题。有人能告诉我一些资源,告诉我在W2k8中使用IIS7运行ASP.net时如何设置目录的写入权限吗

    Edit1:我知道使用集成管道将扩展http管道,使之适用于静态资源和托管资源 http://aspnet.4guysfromrolla.com/articles/122408-1.aspx http://learn.iis.net/page.aspx/243/aspnet-integration-with-iis7/

    我们在产品中使用经典管道,但仍有兴趣了解其他人的经历。

    问题2:在集成模式下使用IIS7会降低性能吗?假设您有两个模块与管道连接,那么性能影响有多大?如果有人能给我指出一些这方面的基线研究,那就太好了。

    2 回复  |  直到 15 年前
        2
  •  0
  •   Ariel    15 年前

    是的,任何类型的文件都会调用它。

    在这些模块中,通常会通过检查HttpContext.Request.Url.AbsolutePath是否包含SharePoint下的“/_布局”,过滤掉您对ex不感兴趣的内容。