How can I redirect to another page from Application_Error
?
At present i am doing
Response.Redirect("~/Account/LogOn");
but i would like to do some thing like RedirectToAction()
How can I redirect to another page from Application_Error
?
At present i am doing
Response.Redirect("~/Account/LogOn");
but i would like to do some thing like RedirectToAction()
Application_Error is not really a designed way to handle errors in MVC application.
The prefered ways are:
Some more links that can be helpful:
Also, I would recommend using ELMAH if you're not using it right now. You can get it as NuGet package.
HttpContext.Current.Response.RedirectToRoute(...)
var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext).Action("ServerError", "Error");
Response.Redirect(urlHelper, true);
Not to mention one shouldn't be redirecting on errors -- you don't want to send HTTP 3xx headers there and you can have nasty redirect loops when things are really going down across the board.