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

时间:2011-11-29 21:38:03

标签: asp.net iis-7 url-routing

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

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

如果我使用.aspx扩展程序点击我的页面,则会触发事件,但是当它没有扩展名时则不会触发。

有没有人知道我要做什么才能在IIS 7中为已路由的无扩展名网址启动Application_AcquireRequestState事件?

1 个答案:

答案 0 :(得分:0)

我相信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()
        {
        }
    }
}