简体   繁体   English

asp.NET-自定义错误消息

[英]asp.NET - Custom Error Messages

I have this code in my web.config file: 我的web.config文件中包含以下代码:

<customErrors defaultRedirect="~/GeneralError.aspx" mode="On">
  <error statusCode="401" redirect="401.aspx" />
  <error statusCode="404" redirect="404.aspx" />
</customErrors>

This works perfectly on my local machine while running IIS and it redirects to my error pages, however when I run it on the server, IIS's default error pages pop in instead of mine. 在运行IIS时,这在我的本地计算机上运行完美,并且重定向到我的错误页面,但是当我在服务器上运行它时,IIS的默认错误页面会弹出,而不是我的。

Why is this? 为什么是这样? How can I fix this? 我怎样才能解决这个问题? Is this something related from the code, or is this some setting on the server? 这与代码有关吗,还是服务器上的某些设置?

This may not be the right solution for your issue, but double check IIS settings (Error Pages) 这可能不是解决您问题的正确方法,但请仔细检查IIS设置(错误页面)

http://blogs.iis.net/rakkimk/archive/2008/10/03/iis7-enabling-custom-error-pages.aspx http://blogs.iis.net/rakkimk/archive/2008/10/03/iis7-enabling-custom-error-pages.aspx

IIS error pages settings override application config. IIS错误页面设置将覆盖应用程序配置。

This format was working for me 这种格式对我有用

<customErrors defaultRedirect="~/GeneralError.aspx" mode="On">
     <error statusCode="401" redirect="~/GeneralError.aspx" />
     <error statusCode="404" redirect="~/GeneralError.aspx" />
</customErrors>

or 要么

<error statusCode="404" redirect="filenotfound.htm" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM