問題描述
我有一個 C# Web 表單 ASP.NET 4.0 Web 應用程序,由于某種原因,我的 web.config 的 system.web 部分中定義的自定義錯誤被完全忽略,它會回退 IIS 錯誤.
I have a C# web forms ASP.NET 4.0 web application that uses Routing for URLs for some reason custom errors defined in the system.web section of my web.config is entirely ignored and it will fall back the IIS errors.
這完全被忽略了
<system.web>
<customErrors mode="On">
<error statusCode="500" redirect="~/Error" />
<error statusCode="404" redirect="~/404" />
<error statusCode="403" redirect="~/Error" />
</customErrors>
</system.web>
這部分接管
<system.webServer>
<httpErrors>
<!--<clear />-->
<remove statusCode="500" subStatusCode="-1" />
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" subStatusCode="-1" path="/App1/404" responseMode="Redirect" />
<error statusCode="500" prefixLanguageFilePath="" path="/App1/Error" responseMode="Redirect" />
</httpErrors>
</system.webServer>
這將是一個小小的不便,除了它回退到 IIS 原生而不是我的應用程序這一事實之外,它完全繞過 Elmah 正確記錄我的 404 異常.
This would be a minor inconvenience except that by the fact it falls back to IIS native instead of my application it completely circumvents Elmah logging my 404 exceptions correctly.
為了避免任何此類建議,我只在 customErrors 停止工作后添加了 httpErrors 配置,所以我會得到任何東西.
Just to avoid any suggestions of such I only added the httpErrors configuration after customErrors stopped working so I would have anything.
推薦答案
要禁用必須設置的 IIS 錯誤消息
To disable the IIS error messages you have to set
Response.TrySkipIisCustomErrors = true;
在您的錯誤頁面中.之后,您的錯誤消息應該沒有問題地顯示.
in your error page. After that, your Error messages should show without problem.
這篇關于IIS7 上托管的 ASP.NET 應用程序忽略自定義錯誤并回退到 IIS 錯誤的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!