gpt4 book ai didi

asp.net-mvc-3 - .NET MVC Server_GetLastError 总是返回缺少 View 错误

转载 作者:行者123 更新时间:2023-12-01 23:25:03 24 4
gpt4 key购买 nike

我正在尝试在 MVC 3 中实现全局未处理的异常日志记录。我已经像这样设置了我的 web.config..

<customErrors mode="On" defaultRedirect="/error/">
<error statusCode="500" redirect="/error/http500"/>
<error statusCode="404" redirect="/error/http404"/>
</customErrors>

当我为 Controller 触发异常时,它会按预期重定向到错误页面。问题是,当我在 Global.asax 中使用 Server.GetLastError() 时,异常总是

"The view 'Error' or its master was not found or no view engine supports the searched locations. The following locations were searched:\r\n~/Views/deanslist/Error.aspx\r\n~/Views/deanslist/Error.ascx\r\n~/Views/Shared/Error.aspx\r\n~/Views/Shared/Error.ascx\r\n~/Views/deanslist/Error.cshtml\r\n~/Views/deanslist/Error.vbhtml\r\n~/Views/Shared/Error.cshtml\r\n~/Views/Shared/Error.vbhtml"

我期待它提供抛出的实际异常。我做错了什么?

最佳答案

尝试从您的 Global.asax 中删除以下行:

filters.Add(new HandleErrorAttribute());

HandleError 属性会拦截 Release 模式下的所有异常,并尝试呈现 Error.cshtml View 。您可能已从 ~/Views/Shared 文件夹中删除了此 View ,因此当抛出未处理的异常时,此异常处理程序会拦截异常并尝试呈现不存在的 View 。

关于asp.net-mvc-3 - .NET MVC Server_GetLastError 总是返回缺少 View 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10473357/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com