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>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM