MVC问题,自定义错误页 [英] MVC problem with custom error pages

查看:262
本文介绍了MVC问题,自定义错误页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用有自定义错误页设置

I have custom error pages setup using

    <customErrors mode="On" defaultRedirect="~/Home/Error">
        <error statusCode="404" redirect="~/Home/PageNotFound" />
    </customErrors>

我创建了一个网页,抛出和异常,我得到重定向到正确的错误页面。

I created a page that throws and exception and I get redirected to the correct error pages.

不过我注意到在对生产网络服务器ELMAH这些错误:
System.InvalidOperationException
视图错误或它的主人没有被发现或没有视图引擎支持搜索到的位置。在以下地点进行了全面搜查:〜/地区/足球/查看/草稿/ Error.aspx〜/地区/足球/查看/草稿/ Error.ascx〜/地区/足球/查看/共享/ Error.aspx〜/地区/足球/Views/Shared/Error.ascx〜/查看/草稿/ Error.aspx〜/查看/草稿/ Error.ascx〜/查看/共享/ Error.aspx〜/查看/共享/ Error.ascx〜/地区/足球/查看/草稿/ Error.cshtml〜/地区/足球/查看/草稿/ Error.vbhtml〜/地区/足球/查看/共享/ Error.cshtml〜/地区/足球/查看/共享/ Error.vbhtml〜/查看/草案/ Error.cshtml〜/查看/草稿/ Error.vbhtml〜/查看/共享/ Error.cshtml〜/查看/共享/ Error.vbhtml

However I am noticing these errors in elmah on the production webserver: System.InvalidOperationException The view 'Error' or its master was not found or no view engine supports the searched locations. The following locations were searched: ~/Areas/Football/Views/Draft/Error.aspx ~/Areas/Football/Views/Draft/Error.ascx ~/Areas/Football/Views/Shared/Error.aspx ~/Areas/Football/Views/Shared/Error.ascx ~/Views/Draft/Error.aspx ~/Views/Draft/Error.ascx ~/Views/Shared/Error.aspx ~/Views/Shared/Error.ascx ~/Areas/Football/Views/Draft/Error.cshtml ~/Areas/Football/Views/Draft/Error.vbhtml ~/Areas/Football/Views/Shared/Error.cshtml ~/Areas/Football/Views/Shared/Error.vbhtml ~/Views/Draft/Error.cshtml ~/Views/Draft/Error.vbhtml ~/Views/Shared/Error.cshtml ~/Views/Shared/Error.vbhtml

为什么要找其他地方的错误页面?我删除〜/查看/共享/ Error.cshtml,因为我在指定我的配置文件中的新默认添加我的自定义错误页在〜/主页/错误。

Why is it looking for the error page elsewhere? I deleted ~/Views/Shared/Error.cshtml and added my custom error page at ~/Home/Error since i specified a new default in my config file.

任何想法?

感谢。

推荐答案

MVC项目默认添加的<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.mvc.handleerrorattribute.aspx\">HandleErrorAttribute在的Global.asax.cs 文件

MVC projects by default adds the HandleErrorAttribute in the Global.asax.cs file

    public static void RegisterGlobalFilters(GlobalFilterCollection filters)
    {
        filters.Add(new HandleErrorAttribute());
    }

当一个未处理的异常时,将执行此过滤器。它集视图错误。因此MVC运行时尝试渲染视图。但是,在你的情况,有没有这样的说法。所以再次抛出一个由ASP.NET运行时进行处理,并显示您在已配置的错误页面另一个异常的Web.Config 文件。

This filter is executed when an unhandled exception is thrown. It sets the view as Error. Hence MVC runtime tries to render that view. But in your case, there is no such view. So it again throws another exception which is handled by ASP.NET runtime and shows your error page that you have configured in Web.Config file.

您可以创建自己的异常过滤器,并进行注册。

You can create your own exception filter and register it.

这篇关于MVC问题,自定义错误页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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