简体   繁体   中英

asp.NET - Custom Error Messages

I have this code in my web.config file:

<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.

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)

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

IIS error pages settings override application config.

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" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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