Question

I am trying to setup custom error for my website which works fine on local-host mode="On".

But same fails on actual website.

Below is my code for web.config

<customErrors mode="RemoteOnly" defaultRedirect="~/error/Message.aspx?msg=The page you requested could not be found.">
  <error statusCode="404" redirect="~/error/Default.aspx?PID=32"/>
  <error statusCode="403" redirect="~/error/Forbidden.aspx"/>
  <error statusCode="400" redirect="~/error/Error.aspx"/>
  <error statusCode="500" redirect="~/error/InternalError.aspx"/>
</customErrors>

I am using IIS 7.5 on my local machine and same is being used on the web server.

Do i need to change any specific setting on Production server to make it work

Error message i am still getting on live website for 404

Not Found
The requested document was not found on this server.
Web Server at xyz.com
Was it helpful?

Solution

Final version with following code worked

...
<customErrors mode="RemoteOnly" defaultRedirect="~/error/Message.aspx?msg=The page you requested could not be found.">
  <error statusCode="404" redirect="~/error/Default.aspx?PID=32"/>
  <error statusCode="403" redirect="~/error/Forbidden.aspx"/>
  <error statusCode="400" redirect="~/error/Error.aspx"/>
  <error statusCode="500" redirect="~/error/InternalError.aspx"/>
</customErrors>

....

<system.webServer>
    <httpErrors errorMode="Custom" existingResponse="Replace">
      <remove statusCode="404" subStatusCode="-1" />
      <error statusCode="404" path="/error/Default.aspx?PID=32" responseMode="ExecuteURL"/>
    </httpErrors>
  </system.webServer>

OTHER TIPS

the web.config part seems to be ok, even if I would suggest static html for default error page redirection.

How do you test this issue on remote server? By typing url xyz.com/xxxxxx where xxxxxx is page which not exist?

If yes, so is xxxxxx without file extension? And does 404 redirect works if xxxxx ends with file extension which is one of website default page? e.g. xxxx.aspx

Try this post asp.net custom error page and file without extension

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top