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>
posted @ 2020-06-13 20:32  willingtolove  阅读(1084)  评论(0编辑  收藏  举报