加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 无法让defaultRedirect工作

发布时间:2020-12-15 22:22:12 所属栏目:asp.Net 来源:网络整理
导读:在我的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 wh
在我的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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读