hotcoder
hotcoder

Reputation: 3246

Handle unhandled exceptions in asp.net

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?

Upvotes: 1

Views: 1031

Answers (3)

John Saunders
John Saunders

Reputation: 161773

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

Upvotes: 4

Justin Morgan
Justin Morgan

Reputation: 30695

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

ASP.NET Custom Error Pages

Upvotes: 2

Mauricio Scheffer
Mauricio Scheffer

Reputation: 99720

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'.

Upvotes: 0

Related Questions