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?
Handle unhandled exceptions in asp.net
1k views Asked by hotcoder AtThere are 3 answers
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'.
<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.
You can do it in Global.asax or you can set up custom error pages in web.config.
ASP.NET Custom Error Pages