Search

Wednesday, April 16, 2014
0 comments

How to make Custom error page in asp.net

12:00 AMWednesday, April 16, 2014
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                     
<system.web>
      <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 ="http://www.google.com">
      <error statusCode ="404" redirect ="errorpage.aspx"/>     
      
    </customErrors>


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


</script>


<html xmlns="http://www.w3.org/1999/xhtml">

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

    </div>

    </form>
</body>
</html>

4. Test your application by generating error 
Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top