开发者

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" r开发者_运维技巧edirect="~/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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜