Is there a way to display a benign error page (using some settings in web.config) when an asp.net app crashes ?
I have an app whose database is updated regularly. If the database is updated while a user is using the app, frequently the app crashes. If the app's webpage is refreshed then everything is OK again.
How best to handle a situation like this? Is there a way to direct all crashes to a webpage that tells the user t开发者_运维问答o just refresh? Thanks.
Yes, you can define and turn on custom error pages.
<customErrors mode="RemoteOnly" defaultRedirect="~\ErrorPages\GenericError.htm">
<error statusCode="403" redirect="~\ErrorPages\NoAccess.htm" />
<error statusCode="404" redirect="~\ErrorPages\PageNotFound.aspx" />
</customErrors>
Set the mode
to On
for all requests or RemoteOnly
to enable custom errors only on remote requests. Then define as many error pages as you need for the various errors.
While you are updating your application, you might consider placing an app_offline.htm
file in the root of your web app. If that file is present it is shown for all incoming requests. See http://weblogs.asp.net/scottgu/archive/2006/04/09/442332.aspx for more info.
The best thing is whenever you want to make any changes on a live website/Database, is to take down the website by putting an app_offline.htm
file in the application folder. The user should not see your application if it crashes.
You could also trap the errors in your global.asax which has a handler for errors, interrogate the error there (using something like Exception ex = Server.GetLastError()) and if it meets the criteria for whatever you're looking for, redirect them to whatever you want.
精彩评论