Asp.Net customErrors与httpErrors的区别
生活随笔
收集整理的這篇文章主要介紹了
Asp.Net customErrors与httpErrors的区别
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
先看一下簡單的對比
customErrors
- Asp.Net級別的錯誤處理程序,只處理Asp.Net應用拋出的異常(404,403,500。。)
- 在IIS7+的服務器依然可用(IIS7之前就引進了)
- 靜態(tài)文件(如.jpg,.htm,.js等)不會被處理
httpErrors
- IIS級別的錯誤信息處理程序,IIS根據(jù)請求指定錯誤頁面
- 自IIS7引進
- 處理包括ASP.NET應用及ASP.NET之外的應用(ASP.NET能管的 它會管,ASP.NET不能管得它也管)
- 所有的文件和URL都處理
從對比中能看出 在IIS7之后 ?就沒必要再用customErrors了,一切httpErrors都可以辦了。
<httpErrors errorMode="Custom" existingResponse="Replace"><remove statusCode="403" subStatusCode="-1" /><remove statusCode="404" subStatusCode="-1" /><error statusCode="403" prefixLanguageFilePath="" path="/403.png" responseMode="ExecuteURL" /><error statusCode="404" path="/404.aspx" responseMode="ExecuteURL" /> </httpErrors>?
其實還可以用一個clear標簽代替多個remove。如下
<httpErrors errorMode="Custom" existingResponse="Replace"><clear /><error statusCode="403" prefixLanguageFilePath="" path="/403.png" responseMode="ExecuteURL" /><error statusCode="404" path="/404.aspx" responseMode="ExecuteURL" /> </httpErrors>?
?
Note:ExecuteURL?只能用于同一個應用下的ASP.NET文件,如果想要重定向到另一個應用,或者一個完全不一樣的完整的URL,我們需要將responseMode設為Redirect。
<httpErrors errorMode="Custom" existingResponse="Replace"><clear /><error statusCode="404" path="http://www.bing.com" responseMode="Redirect"/> </httpErrors>?
?
?
?
?
現(xiàn)在通過不同的URL來看兩者的區(qū)別
給Web應用定義如下配置
<system.web><customErrors mode="On" defaultRedirect="Error.html"><error statusCode="403" redirect="/Error403" /><error statusCode="404" redirect="/Error404" /><error statusCode="500" redirect="/Error500" /></customErrors> </system.web> <system.webServer><httpErrors errorMode="Custom" existingResponse="Auto" defaultResponseMode="ExecuteURL" ><remove statusCode="403"/><remove statusCode="404"/><remove statusCode="500"/><error statusCode="403" responseMode="ExecuteURL" path="/Error403" /><error statusCode="404" responseMode="ExecuteURL" path="/Error404" /><error statusCode="500" responseMode="ExecuteURL" path="/Error500" /></httpErrors> </system.webServer>現(xiàn)在如果嘗試訪問以下鏈接,將會產(chǎn)生對應的錯誤
| URL | Error | StatusCode |
| /aaaaaa? | httpErrors? | 404 |
| /aaaaaa.aspx | customErrors? | 404 |
| /aaaaaa.jpg | httpErrors? | 404 |
| /throw500.apx | customErrors? | 500 |
| /throw500 | customErrors? | 500 |
?
?
?
?
?
注:
?
?
?相關(guān)參考:
Custom 404 and error pages in ASP.NET
IIS.NET ?HTTP Errors
?
轉(zhuǎn)載于:https://www.cnblogs.com/TiestoRay/p/4723996.html
總結(jié)
以上是生活随笔為你收集整理的Asp.Net customErrors与httpErrors的区别的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Hacking Team Flash 0
- 下一篇: javascript继承机制