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