Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net mvc on azure - trouble with customErrors

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));
}
like image 425
Toodleey Avatar asked Nov 22 '11 09:11

Toodleey


1 Answers

this did the trick:

Response.TrySkipIisCustomErrors = true;
like image 54
Toodleey Avatar answered Nov 10 '22 16:11

Toodleey