【发布时间】:2011-11-08 01:48:12
【问题描述】:
我有自定义错误页面设置使用
<customErrors mode="On" defaultRedirect="~/Home/Error">
<error statusCode="404" redirect="~/Home/PageNotFound" />
</customErrors>
我创建了一个抛出异常的页面,然后我被重定向到正确的错误页面。
但是我在生产网络服务器上的 elmah 中注意到这些错误:
System.InvalidOperationException 视图“错误”或其主视图是 未找到或没有视图引擎支持搜索的位置。这 搜索了以下位置: ~/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
为什么要在别处寻找错误页面?我删除了 ~/Views/Shared/Error.cshtml 并在 ~/Home/Error 中添加了我的自定义错误页面,因为我在我的配置文件中指定了一个新的默认值。
有什么想法吗?
谢谢。
【问题讨论】:
-
因为
customErrors是 ASP.NET 处理的东西(不是 ASP.NET MVC),所以它不是完成这项工作的最佳工具。 Richard Dingwall 对此有一篇出色的文章:richarddingwall.name/2008/08/17/…
标签: asp.net-mvc asp.net-mvc-routing