user354625
user354625

Reputation: 557

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..

Thanks

Upvotes: 3

Views: 7134

Answers (2)

James Antrobus
James Antrobus

Reputation: 409

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

Upvotes: 1

Dustin Laine
Dustin Laine

Reputation: 38503

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

Upvotes: 1

Related Questions