Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redirect from Application_Error

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()

like image 802
Kuttan Sujith Avatar asked Dec 29 '22 00:12

Kuttan Sujith


2 Answers

Application_Error is not really a designed way to handle errors in MVC application.

The prefered ways are:

  • HandleErrorAttribute
  • Controller.OnException

Some more links that can be helpful:

  • ASP.NET MVC HandleError
  • http://www.davidjuth.com/asp-net-mvc-error-handler.aspx
  • http://blog.dantup.com/2009/04/aspnet-mvc-handleerror-attribute-custom.html

Also, I would recommend using ELMAH if you're not using it right now. You can get it as NuGet package.

like image 139
Jakub Konecki Avatar answered Jan 10 '23 12:01

Jakub Konecki


HttpContext.Current.Response.RedirectToRoute(...)
like image 45
Alexandre Avatar answered Jan 10 '23 13:01

Alexandre