How to make Custom error page in

April 16, 2014 0 Comments

If the error isn't properly handled anywhere ,it generates an ugly error message that your visitor will see -- you don't want this to happen

So add a custom error page to your site that your visitor will see in case an unhandled error happens. That page will politely ask the visitor to come back later.

Report the error once again , so the Administrator knows that this serious error gets to the visitor and needs to be taken care of as soon as possible.

Steps to follow for add custom error page:

  1. In Solution Explorer , Double-click web.config and add the following element as a child of the                     
      <customErrors mode ="RemoteOnly"  defaultRedirect ="errorpage.aspx" />

Note : If you want to handle errors using status code then specifies status code in <error> tag. Like

<customErrors mode ="On" defaultRedirect ="">
      <error statusCode ="404" redirect ="errorpage.aspx"/>     

2. Add a new web form to your application's root , named errorpage.aspx . This form should not use a Master page , to make sure nothing gets in the way of displaying out simple error . The page also doesn't need a code-behind file

Note: After this change , remote clients will be forwarded to errorpage.aspx when unhandled exceptions are thrown ; however on the local machine you will still receive detailed error information . if you want to see the same error message as your visitors , set mode to On instead of RemoteOnly

3. Write some message into your errorpage.aspx like

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">


<html xmlns="">

<head runat="server">
    <form id="form1" runat="server">
   Your requested generated an error message 
        we apolgize for the inconvenience.



4. Test your application by generating error 

Jacob Lefore

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google