I've been banging my head against this for a few days without getting anywhere. I want to have a catch all error handler that redirects to a controller which displays a neat page to the user as well as do relevant logging and such.
The thing is that everything works just fine locally, but when I upload to azure I get the standard error pages instead.
It seems like azure does not execute the redirect, and ignores the global handler in global.asax as well.
I did not include the code for the error controller here as it seems I never get that far.
Web.Config:
<customErrors mode="On" defaultRedirect="/error" redirectMode="ResponseRewrite"></customErrors>
Route entry:
routes.MapRoute("Error", "error/{*fluff}", new { controller = "Error", action = "Index", exception = new HttpException(404,"Direct call to controller") });
From global.asax:
protected void Application_Error(object sender, EventArgs e)
{
var routeData = new RouteData();
routeData.Values["controller"] = "Error";
routeData.Values["action"] = "index";
routeData.Values["exception"] = Server.GetLastError();
Response.Clear();
Server.ClearError();
IController controller = new ErrorController();
controller.Execute(new RequestContext(new HttpContextWrapper(((MvcApplication)sender).Context), routeData));
}
this did the trick:
Response.TrySkipIisCustomErrors = true;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With