Tutorial :How to redirect the Error page in asp.net mvc


Hello friends I have this code in my web config file.. I am new to asp.net mvc.

<customErrors mode="On" defaultRedirect="~/Shared/Error">        <error statusCode="403" redirect="~/Shared/Error" />        <error statusCode="404" redirect="~/Shared/Error" />      </customErrors>  

and I have Error.aspx page under Shared Folder in my application..

now My question is Do i need to do anything with Global.ascx file to route?

if so how to route? waht exactly need to define in my global.ascx file..



To catch errors based on status code this should work fine. For other errors thrown in your application you can add the HandleError attribute to your controller - this will by default redirect to your Error page in ~/Views/Shared/ or to a specified view if given.

[HandleError]  public class HomeController : Controller  

See MSDN for more information: http://msdn.microsoft.com/en-us/library/system.web.mvc.handleerrorattribute.aspx


As long as you have the default route it should work fine. Are you having problems.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »