#事故現場
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>