asp.net mvc - Redirect to Error Page Fail on Application Error in Global.asax (MVC) -


i having hard time trying redirect error handling controller when application error encountered in global.asax.

here routecollection

    routes.ignoreroute("{resource}.axd/{*pathinfo}");      routes.maproute(         "default", // route name         "{controller}/{action}/{id}", // url 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 global.asax application_error has this

                this.context.response.clear();                 this.context.clearerror();                 //this.response.redirect("~/hndlerror/allerrors") // 1 works !!!                   this.response.redirecttoroute( new { controller = "hndlerror",  action = "allerrors", id = errormessage }); // not work                  this.response.end(); 

my controller action hit while using response.redirect returns blank page redirecttoroute . did more searching , came across gem !

beware of responseredirecttoroute in mvc 3

does mean not work in mvc3 or missing ? please help.

thanks

try following:

protected void application_error(object sender, eventargs e) {     httpcontext ctx = httpcontext.current;     ctx.response.clear();     requestcontext rc =((mvchandler)ctx.currenthandler).requestcontext;     rc.routedata.values["action"] = "allerrors";      rc.routedata.values["controller"] = "hndlerror";     rc.routedata.values["id"] = errormessage ;      icontrollerfactory factory = controllerbuilder.current.getcontrollerfactory();     icontroller controller = factory.createcontroller(rc, "hndlerror");     controller.execute(rc);     ctx.server.clearerror(); } 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -