Ryan S
Ryan S

Reputation: 3268

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?

Upvotes: 1

Views: 805

Answers (2)

huMpty duMpty
huMpty duMpty

Reputation: 14460

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

Upvotes: 0

Daryl Teo
Daryl Teo

Reputation: 5495

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.

Upvotes: 1

Related Questions