JS、图像和CSS被HTTPModule拦截

发布于 2024-08-18 08:08:51 字数 1788 浏览 5 评论 0 原文

我有一个简单的 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 - cassini服务器

PS:我确实在我们的沙箱(有点新)中使用Win2k8 IIS7尝试过,并尝试将其写入日志文件(因为我们那里没有VS),但无法写入日志文件。我确定它有一些写入权限问题。任何人都可以向我指出一些资源,告诉我如何在 W2k8

Edit1 中使用 IIS7 运行 ASP.net 时设置目录的写入权限:我知道使用集成管道会扩展静态和托管资源的 http 管道 https://web.archive .org/web/20210612113955/https://aspnet.4guysfromrolla.com/articles/122408-1.aspxhttp://learn.iis.net/page.aspx/243/aspnet-integration-with-iis7/

我们在我们的项目中使用经典管道产品。但仍然有兴趣了解其他人经历过的事情。

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

じ违心 2024-08-25 08:08:51

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文