How to show custom error page for 404 error in your application

Create your owrn custom error page may be a simple aspx file which show an common error message add it in the root folder where your web config is exist.(HttpErrorPage.aspx)



1.Add following in web.config under the system.web

<system.web>
    <customErrors defaultRedirect="~\HttpErrorPage.aspx" mode="On">
    </customErrors>
</system.web>

2.Add following into IIS infocenter web site.

-Go to InfoCenter site in IIS
-Double Click on Error Pages icon in Features View.
-Right Click “Add
 -Set the status code – 404
-Tick the Execute a URL on this site and the path as “/Virtual Folder name of the site/HttpErrorPage.aspx
-Click OK.
-When you adding these configurations will added in to web config file automatically so you may need to accept the changes and save it.

So likewise you can add multiple pages for different Http errors etc:- 403,402,401,501..

Test: generate a 404 error,it will take you to the custom error page
Ex:- localhost\sitename\balalala.aspx

No comments:

Post a Comment