Hello friends I have this code in my web config file.. I am new to asp.net mvc.
朋友们,我的web配置文件中有这段代码。我对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..
我有错误。在我的应用程序的共享文件夹下的aspx页。
now My question is Do i need to do anything with Global.ascx file to route?
现在我的问题是,我是否需要对Global做任何事情。ascx文件路由?
if so how to route? waht exactly need to define in my global.ascx file..
如果是的话,怎么走?我需要在全局中定义什么。ascx文件. .
Thanks
谢谢
2 个解决方案
#1
1
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属性添加到控制器中——如果给定的话,该属性将默认重定向到~/Views/Shared/或指定视图中的错误页面。
[HandleError]
public class HomeController : Controller
See MSDN for more information: http://msdn.microsoft.com/en-us/library/system.web.mvc.handleerrorattribute.aspx
更多信息请参见MSDN: http://msdn.microsoft.com/en-us/library/system.web.mvc.handleerrorattribute.aspx
#2
1
As long as you have the default route it should work fine. Are you having problems.
只要您有默认的路由,它就可以正常工作。你有问题。
#1
1
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属性添加到控制器中——如果给定的话,该属性将默认重定向到~/Views/Shared/或指定视图中的错误页面。
[HandleError]
public class HomeController : Controller
See MSDN for more information: http://msdn.microsoft.com/en-us/library/system.web.mvc.handleerrorattribute.aspx
更多信息请参见MSDN: http://msdn.microsoft.com/en-us/library/system.web.mvc.handleerrorattribute.aspx
#2
1
As long as you have the default route it should work fine. Are you having problems.
只要您有默认的路由,它就可以正常工作。你有问题。