asp.net html静态文件没有触发global.asax中的Application_BeginRequest事件的解决方法

Posted willingtolove

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了asp.net html静态文件没有触发global.asax中的Application_BeginRequest事件的解决方法相关的知识,希望对你有一定的参考价值。


#事故现场

asp.net的网站,需要拒绝掉所有指向html的请求,当有html请求时,跳转到指定页面,可以在global.asax里这样写:

<%@ Assembly Name="System.Web"%>

<script runat="server">
void Application_BeginRequest(object sender, EventArgs e)
{
        if (Request.Url.ToString().EndsWith(".html"))
        {
            Response.Redirect("http://www.baidu.com");
        }
}
</script>

结果当访问.html页面时,没有触发Application_BeginRequest事件;

#解决方法

在web.config中添加如下配置:

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
</system.webServer>

以上是关于asp.net html静态文件没有触发global.asax中的Application_BeginRequest事件的解决方法的主要内容,如果未能解决你的问题,请参考以下文章