Search This Blog

Monday 30 April 2012

How to show error page in ASP.Net


Handle custom errors in ASP.Net

Once the ASP.Net application is ready to launh to customers, there is no need to show the error details in to the web page when any errors occurred. In this scenario we can show our customised page with details like “Server is busy now please after some time” to the customer. At the same time we can store error details to database or txt file for future reference for developers. For customise errors in the ASP.Net we need to do some settings in the web.config file.

Settings on web.config to show error page

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

The above code should be placed in the web.config file for handling custom errors (mode=”On”). Also we can handling particular erros with error code with appropriate error page. In above mentioned code, if a user request a page that is not in the server, 404 error is occurred then page is automatically direct to 404Error.aspx. If any other errors occurred, it will show web page error.aspx. In the same way we can handle any type of error with the status code, with the appropriate web page. 

No comments:

Post a Comment