If you have custom errors set to RemoteOnly
in web config - does this mean that MVC's application level error event in global.asax
- Application_Error
is not fired on error?
I have just noticed that when a certain error occurs in my application, and I am viewing the site remotely, no error is logged. However, when I am accessing the app on the server and the same error occurs, the error is logged.
this is the custom errors config setting:
<customErrors defaultRedirect="/Error/Application" mode="RemoteOnly">
<error statusCode="403" redirect="/error/forbidden"/>
<error statusCode="404" redirect="/error/notfound"/>
<error statusCode="500" redirect="/error/application"/>
</customErrors>
EDIT
Just out of interest for people - I ended up completely turning off custom errors and dealing with redirection in Application_Error
like so:
protected void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
// ... log error here
var httpEx = exception as HttpException;
if (httpEx != null && httpEx.GetHttpCode() == 403)
{
Response.Redirect("/youraccount/error/forbidden", true);
}
else if (httpEx != null && httpEx.GetHttpCode() == 404)
{
Response.Redirect("/youraccount/error/notfound", true);
}
else
{
Response.Redirect("/youraccount/error/application", true);
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…