ASP.NET MVC HandleError 视图未找到

发布于 2024-10-18 14:35:02 字数 694 浏览 5 评论 0原文

我正在尝试使用 HandleError 属性在 ASP.NET MVC3 中实现异常处理。

我使用的代码如下所示:

[HandleError(Order = 1, ExceptionType = typeof(SocketsOfflineException), View="EndSystemDownError")]

当 EndSystemDownError 视图位于“Shared”文件夹中时,它会按预期工作。但是,我有许多错误视图,我想将它们单独放入一个专门用于错误的文件夹中,称为“错误”。

因此,我将 EndSystemDownError 视图从共享文件夹中拉出并放入 Views 文件夹中的“Error”子文件夹中。然后,我将 View 属性更新为 ~/Views/Error/EndSystemDownError。然而,这会导致异常,指出未找到该视图。我也尝试了 /Views/Error/EndSystemDownError ,结果相同。

我尝试添加带有 EndSystemDownError 操作的 ErrorController ,既作为故障排除措施,又因为我想向视图添加一些控制器功能。这没有效果。

我似乎无法弄清楚我做错了什么。也许这是 MVC 中的一个错误,或者它可能不支持共享文件夹之外的错误视图,这将令人失望。

I'm trying to implement exception handling in ASP.NET MVC3 using the HandleError attribute.

The code that I'm using looks like this:

[HandleError(Order = 1, ExceptionType = typeof(SocketsOfflineException), View="EndSystemDownError")]

This works as expected when the EndSystemDownError view is located in the "Shared" folder. However, I have a number of Error views, and I want to separate them out into a folder specifically for Errors, called "Error".

So I pull the EndSystemDownError view out of the shared folder and into an "Error" subfolder in the Views folder. I then update the View property to ~/Views/Error/EndSystemDownError. This however results in an exception stating that the view was not found. I tried /Views/Error/EndSystemDownError as well, with the same results.

I have tried adding an ErrorController with an EndSystemDownError action, both as a troubleshooting measure, and because I would like to add some controller functionality to the view. This has no effect.

I can't seem to figure out what I'm doing wrong. Perhaps this is a bug in MVC, or maybe it doesn't support error views outside of the Shared folder, which would be disappointing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

○愚か者の日 2024-10-25 14:35:02

AFAIK 您无法修改这些视图的位置。它们应该位于 ~/Views/Shared 中。您可以指定每个异常类型的名称:

[HandleError(
    Order = 1, 
    ExceptionType = typeof(SocketsOfflineException), 
    View = "EndSystemDownError"
)]

其中 EndSystemDownError 视图位于 ~/Views/Shared/EndSystemDownError.aspx 中。

AFAIK you cannot modify the location of those views. They should be in ~/Views/Shared. You could specify the name though per exception type:

[HandleError(
    Order = 1, 
    ExceptionType = typeof(SocketsOfflineException), 
    View = "EndSystemDownError"
)]

where the EndSystemDownError view is located in ~/Views/Shared/EndSystemDownError.aspx.

猥琐帝 2024-10-25 14:35:02

如果将错误子文件夹放在共享文件夹中,则可以通过 Errors/whatevererror.aspx 引用它,应该没问题。

我经常这样做。毕竟他们是共同的观点。 :)

If you put your errors subfolder inside of the shared folder, you can refer to it by Errors/whatevererror.aspx and it should be fine.

I do this frequently. After all they are shared views. :)

关于从前 2024-10-25 14:35:02

你试过吗

[HandleError(Order = 1, ExceptionType = typeof(SocketsOfflineException), View="Error/EndSystemDownError")]

did you try

[HandleError(Order = 1, ExceptionType = typeof(SocketsOfflineException), View="Error/EndSystemDownError")]
笑梦风尘 2024-10-25 14:35:02

Orchard 模块编程的旁注:

HandleError 属性在 Orchard 模块中不起作用,因为 Orchard 实现了自定义过滤器处理本身。

您需要实现一个 FilterProvider 来重写 OnResultExecuted() 以捕获视图中引发的异常。

参见src\Orchard\Exceptions\Filters\UnhandledExceptionFilter.cs,它实现了常见的Orchard错误页面。

Side note for Orchard module programming:

The HandleError attribute won't work in Orchard modules as Orchard implements a custom filter handling itself.

You need to implement a FilterProvider that overrides the OnResultExecuted() to catch exceptions thrown in a view.

See src\Orchard\Exceptions\Filters\UnhandledExceptionFilter.cs, it implements the common Orchard error page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文