不能得到的defaultRedirect工作 [英] Can't get defaultRedirect to work

查看:242
本文介绍了不能得到的defaultRedirect工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的web.config,我有:

In my web.config, I have:

<system.web>
    <customErrors mode="On" defaultRedirect="Error.cshtml" />
</system.web>

在查看/共享/ Error.cshtml,我有:

In Views/Shared/Error.cshtml, I have:

@model System.Web.Mvc.HandleErrorInfo
@{
    ViewBag.Title = "Error";
}
<h2>
    Sorry, an error occurred while processing your request.
</h2>

如果我把一个无效的URL /路由到我的浏览器,我得到这样的:

If I put an invalid URL/route into my browser, I get this:

中的服务器错误'/'应用。

Server Error in '/' Application.

资源无法找到。

说明:HTTP 404。您正在寻找(或它的一个依赖)可能已被删除的资源,更名或暂时不可用。请检查以下URL并确保其拼写正确。

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.

请求的URL:/Error.cshtml

Requested URL: /Error.cshtml

为什么不能Error.cshtml找到?该文件绝对是查看/共享。

Why can't Error.cshtml be found? The file is definitely in Views/Shared.

推荐答案

的defaultRedirect中不会直接去查看。您的defaultRedirect看起来像它无法处理的Razor视图文件。例如:它在哪里,从得到的模型?这是不,不能,在配置文件中指定,因此无法处理的视图。

The defaultRedirect won't go directly to a view. Your defaultRedirect looks like a razor view file which it can't process. For example: Where does it get the model from? It isn't, and can't, be specified in the config file so it can't process a view.

如果你想在MVC更加动态的错误页面,你可能需要阅读的自定义错误页和错误处理MVC 3

If you want more dynamic error pages in MVC you might want to read custom error pages and error handling in MVC 3

这篇关于不能得到的defaultRedirect工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆