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

时间:2020-06-13 21:07:05   收藏:0   阅读:68

#事故现场

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>

原文:https://www.cnblogs.com/willingtolove/p/13121676.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!