在我的web.config中,我有:
<system.web> <customErrors mode="On" defaultRedirect="Error.cshtml" /> </system.web>
在Views / Shared / Error.cshtml中,我有:
@model System.Web.Mvc.HandleErrorInfo @{ ViewBag.Title = "Error"; } <h2> Sorry,an error occurred while processing your request. </h2>
如果我将无效的URL /路由放入浏览器中,我得到:
Server Error in ‘/’ Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed,had its name changed,or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /Error.cshtml
为什么找不到Error.cshtml?该文件绝对在视图/共享.
解决方法
defaultRedirect不会直接转到视图.您的defaultRedirect看起来像一个无法处理的剃刀视图文件.例如:从哪里得到模型?在配置文件中不能指定,也不能指定,因此无法处理视图.
如果您想在MVC中有更多动态错误页面,您可能需要阅读custom error pages and error handling in MVC 3
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。