Global.asax 事件在带有 .net 4 路由的 IIS 7 集成模式下未触发

发布于 2024-12-18 13:30:44 字数 279 浏览 2 评论 0原文

我刚刚切换到使用 Server 2008/IIS 7。我正在集成模式下运行我的应用程序。我正在使用 .Net 4.0 路由功能并使用无扩展名的 url。

我的问题是 global.asax 文件中 BeginRequest 之后的事件不会触发。

如果我使用 .aspx 扩展名访问我的页面,则事件会触发,但如果页面没有扩展名,则事件不会触发。

有谁知道我必须做什么才能让 Application_AcquireRequestState 事件在 IIS 7 中针对路由的、无扩展名的 URL 触发?

I just switched over to using Server 2008/IIS 7. I am running my application in integrated mode. I am using the .Net 4.0 routing feature and using extension-less urls.

My problem is that the events in the global.asax file that are after the BeginRequest don't fire.

The events fire if I hit my page using an .aspx extension but not when it doesn't have an extension.

Does anyone know what I have to do to get the Application_AcquireRequestState event to fire for routed, extension-less urls in IIS 7?

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

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

发布评论

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

评论(1

凤舞天涯 2024-12-25 13:30:44

我相信 Global.asax 中的事件仅针对由标准 HttpHandler (从 Page 类派生的对象)处理的请求触发。

要接收每个请求的事件,您应该创建并注册一个 HttpModule

using System;
using System.Web;

namespace Sample
{
    public class SampleModule : IHttpModule
    {
        public void Init(HttpApplication context)
        {
            context.AcquireRequestState += OnAcquireRequestState;
        }

        void OnAcquireRequestState(object sender, EventArgs e)
        {
        }

        public void Dispose()
        {
        }
    }
}

I believe the events in Global.asax only fire for requests that are processed by the standard HttpHandler (objects derived from the Page class).

To receive events for every request, you should create and register an HttpModule.

using System;
using System.Web;

namespace Sample
{
    public class SampleModule : IHttpModule
    {
        public void Init(HttpApplication context)
        {
            context.AcquireRequestState += OnAcquireRequestState;
        }

        void OnAcquireRequestState(object sender, EventArgs e)
        {
        }

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