Handle unhandled exceptions in asp.net

1k views Asked by At

How can we prevent page crash in asp.net? Is there any generic function or place like global.asax where we specify a file to redirect to when an unhanded exception occurs? (like we redirect to a specified page when 404 page not found exception occurs?

3

There are 3 answers

1
Justin Morgan On BEST ANSWER

You can do it in Global.asax or you can set up custom error pages in web.config.

ASP.NET Custom Error Pages

0
Mauricio Scheffer On

How can we prevent page crash in asp.net?

As Mal said, "If it crashes, you crashed it". The only way to "prevent" crashes is by carefully writing your code, testing, etc, as with any program.

To display a nice error page, check out the <customErrors> element in your web.config. MSDN docs here. Plenty of articles around if you google for 'customErrors'.

0
John Saunders On

<customErrors> doesn't prevent your pages from "crashing". It just allows you to apologize to your users when the page does crash.

You should be examining the Application event log for messages from the source "ASP.NET <version>". These will include details of any exceptions your code has been generating and not handling. You need to fix these, as every one of these indicates that your users were not able to do what they came to your site to do.