Reputation: 1463
I have the following customErrors section in my ASP.NET application:
<customErrors mode="RemoteOnly">
<error statusCode="500" redirect="500.aspx"/>
</customErrors>
How do I show user-friendly message, if "500.aspx" gives an error (it could happen when the database is down, for example)?
Upvotes: 0
Views: 127
Reputation: 124696
You can use a static page (e.g. 500.html) to avoid this problem.
In response co comment:
I would like to use static page ONLY when "500.aspx" doesn't work.
The only sure way to know if 500.aspx is going to work is to try it. So in this case, you could define 500.aspx in the customErrors
element of web.config, and handle the specific case of 500.aspx in global.asax, e.g. :
void Application_Error(object sender, EventArgs e)
{
HttpException httpException = Server.GetLastError() as HttpException;
if (httpException == null) return;
int httpCode = httpException.GetHttpCode();
if (httpCode == 500 &&
Request.Path.EndsWith("/500.aspx", StringComparison.OrdinalIgnoreCase))
{
Server.ClearError();
Response.Redirect("~/500.htm");
}
}
Upvotes: 1
Reputation: 3574
If you create one errorpage and always let the user end up there. Or do you want each statusCode a specific page? You can even add a mail-method to inform you about certain errors if you like.
Upvotes: 0