mercredi 8 juillet 2015

Redirect to Error Page Fail on Application Error in Global.asax (MVC)

I am having a hard time trying to redirect to my error handling controller when an application error is encountered in Global.asax.

Here is my RouteCollection

    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
        new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
    );

    routes.MapRoute(
        "DefaultError",
        "{controller}/{action}/{id}",
        new { controller = "HndlError", action = "AllErrors", id = UrlParameter.Optional }
        );

And My Global.asax Application_Error has this

                this.Context.Response.Clear();
                this.Context.ClearError();
                //this.Response.Redirect("~/HndlError/AllErrors") // This one Works !!!


                this.Response.RedirectToRoute( new { controller = "HndlError",
 action = "AllErrors", id = ErrorMessage }); // This does not Work

                this.Response.End();

My Controller Action does get hit while using Response.Redirect but returns a blank page with RedirectToRoute . Did some more searching and then came across this GEM !

Beware of ResponseRedirectToRoute in MVC 3

Does that mean it will not work in MVC3 or am i missing something ? Please Help.

thanks

Aucun commentaire:

Enregistrer un commentaire