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

前端之家收集整理的这篇文章主要介绍了asp.net-mvc – 无法让defaultRedirect工作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在我的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

原文链接:https://www.f2er.com/aspnet/249052.html

猜你在找的asp.Net相关文章