ASP.NET MVC 错误处理 - 视图永远不会呈现,Web.config 问题?
我在其中一个控制器上指定了一个 [HandleError] 属性,指定了我想要在发生错误时呈现的视图。
我的 web.config 中还有以下配置部分:
<customErrors mode="On">
<error statusCode="404" redirect="~/Error/NotFound"/>
<error statusCode="500" redirect="~/Error/Unknown"/>
</customErrors>
无论发生什么,mvc 都会在 customErrors 部分中呈现视图。 由于某种原因我无法覆盖视图。
另外,在视图呈现时我已经丢失了所有上下文信息。
不确定我做错了什么或者其他人是否遇到过这个问题。
ps:我还确认了我尝试重定向到的视图中没有任何错误。非常郁闷的问题!
I have a [HandleError] attribute specified atop one of my controllers, specifying a View that I'd like to render in the event of an error.
I also have the following config section in my web.config:
<customErrors mode="On">
<error statusCode="404" redirect="~/Error/NotFound"/>
<error statusCode="500" redirect="~/Error/Unknown"/>
</customErrors>
No matter what happens, mvc renders the view in the customErrors section.
I cannot override the View for some reason.
Also, I've lost all contextual information by the time the view renders.
Not sure what I'm doing wrong or if someone else has experienced this problem.
ps: I've also confirmed the Views that I'm trying to redirect to don't have any errors in them. Very frusterating problem!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对不起,是我的错。
事实证明,视图本身存在错误,导致重定向到 customErrors url。
哎哟!
Sorry, my fault.
Turns out there was an error in the view itself which was resulting in a redirect to the customErrors url.
Doh!