Asp.Net customErrors与httpErrors的区别 先看一下简单的对比

【转】Asp.Net customErrors与httpErrors的区别
https://www.cnblogs.com/TiestoRay/p/4723996.html

先看一下简单的对比

customErrors

Asp.Net级别的错误处理程序,只处理Asp.Net应用抛出的异常(404,403,500。。)
在IIS7+的服务器依然可用(IIS7之前就引进了)
静态文件(如.jpg,.htm,.js等)不会被处理
httpErrors

IIS级别的错误信息处理程序,IIS根据请求指定错误页面
自IIS7引进
处理包括ASP.NET应用及ASP.NET之外的应用(ASP.NET能管的 它会管,ASP.NET不能管得它也管)
所有的文件和URL都处理
从对比中能看出 在IIS7之后 就没必要再用customErrors了,一切httpErrors都可以办了。

复制代码






复制代码

其实还可以用一个clear标签代替多个remove。如下

复制代码





复制代码

Note:ExecuteURL 只能用于同一个应用下的ASP.NET文件,如果想要重定向到另一个应用,或者一个完全不一样的完整的URL,我们需要将responseMode设为Redirect。

复制代码




复制代码

现在通过不同的URL来看两者的区别

给Web应用定义如下配置

复制代码
<system.web>





</system.web>
<system.webServer>








</system.webServer>
复制代码
现在如果尝试访问以下链接,将会产生对应的错误

URL Error StatusCode
/aaaaaa httpErrors 404
/aaaaaa.aspx customErrors 404
/aaaaaa.jpg httpErrors 404
/throw500.apx customErrors 500
/throw500 customErrors 500

注:

一般情况 customErrors标签上的model属性设为RemoteOnly,httpErrors上的errorModel设为DetailedLocalOnly
如果你将某个页面的StatusCode设为500,不要忘了设置如下属性
context.Response.TrySkipIisCustomErrors = true;

Make sure HTTP errors is enabled in IIS
For this to work you have to make sure the HTTP Errors feature is installed for IIS, otherwise you’ll just get an empty 404 response:
在这里插入图片描述

相关参考:

Custom 404 and error pages in ASP.NET
https://tedgustaf.com/blog/2011/custom-404-and-error-pages-for-asp-net-and-static-files/

IIS.NET HTTP Errors
https://docs.microsoft.com/en-us/iis/configuration/system.webServer/httpErrors/

Guess you like

Origin blog.csdn.net/carcarrot/article/details/120848896