5
我有一個以傳統流水線模式運行.NET 4.0的IIS 7.5網站。Application_BeginRequest未在生產服務器上爲JPG激活
我創建了一個簡單的默認圖像設置,其中如果圖像在Application_BeginRequest
事件中使用下面的代碼調用,但物理文件不存在的請求重定向到一個默認的圖像:
protected void Application_BeginRequest(object sender, EventArgs e)
{
if (Request.PhysicalPath.EndsWith(".jpg") && File.Exists(Request.PhysicalPath) == false)
{
Context.RewritePath("~/images/nophoto.jpg");
}
}
這在我的VS2010開發服務器上工作正常,但是在生產環境中,不會爲JPG請求調用Application_BeginRequest事件,我所得到的只是標準的HTTP錯誤404.0 - 未找到錯誤。
我已經嘗試設置在web.config中真runAllManagedModulesForAllRequests
選項,但這似乎並沒有幫助:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"></modules>
</system.webServer>
從我的理解這一點應引起所有請求要經過.NET,因此觸發Application_BeginRequest事件?
期望的結果:
我想所有的請求要經過.NET從而使的Application_BeginRequest事件被稱爲爲JPG文件,如果沒有圖像發現返回的默認圖像。
謝謝,這樣做! – antfx