How to set custom error pages


User wants to set custom pages that will be returned when visitors to their site encounter errors, such as 500 Internal Server Error.


Use one of the two following methods:

Configuring ASP.NET Error Pages

Open up your web.config file and navigate to the customErrors section. Update your customErrors node to be similar to the following: 
<customErrorsmode="RemoteOnly"> <errorstatusCode="404"redirect="/404.aspx"/> </customErrors>

  • The statusCode node is the status code you want to trap. In this case, 404 is the status code for Page Not Found.
  • The redirect is the URL you want to send users to.  In this case, it is /404.aspx (assuming this URL exists).

Alternate Complete Solution

This solution provides an easy fix that encompasses ALL errors.
Open up your web.config file and navigate to the CustomErrors section. Update your customErrors node to be similar to the following:


One thing to note is that this method will encompass ALL of your errors. What this line does is provide a generic document for any error that is not directly specified.

To specify a certain status code, you will need this line to be modified to look similar to the following:

<customErrorsdefaultRedirect="GenericError.html"mode="On"> <errorstatusCode="500"redirect="InternalError.htm"/> <errorstatusCode="http_error_code"redirect="/path_to_error_file"/> </customErrors>

It is necessary to specify any error codes you would like to have custom documents, else a generic page will be given by the defaultRedirect attribute given to the customErrors element in the opening tag.


Credit: Alexander Lunin



Please sign in to leave a comment.