ASP.NET MVC HandleError 和其他属性的操作顺序
我试图让 HandleError 属性正常工作,但由于某种特殊情况,我遇到了一些困难。
我有另一个属性,它会检查数据库中的 IP 黑名单,并确实抛出异常。我希望使用 HandleError 属性捕获该异常并路由到错误页面,但它不起作用。
我认为操作顺序可能是我需要的,但它似乎也不起作用...我尝试过:
[Custom(Order = 1), HandleError(Order = 2)]
Controller...
并且:
[HandleError(Order = 1), Custom(Order = 2)]
Controller...
似乎都没有捕获异常。如果有人有任何建议,我将不胜感激,提前致谢!
I'm trying to get the HandleError attribute to work, but I'm having some difficulty because of a sort of a special circumstance.
I have another attribute which checks against a blacklist of IPs in my database and quite literally throws an exception. I was hoping to catch that exception with the HandleError attribute and route to the Error page, but it's not working.
I thought that the order of operations might be what I need, but it doesn't seem to work either... I tried:
[Custom(Order = 1), HandleError(Order = 2)]
Controller...
And:
[HandleError(Order = 1), Custom(Order = 2)]
Controller...
Neither seem to catch the exception. If anyone has any suggestions, I would appreciate them, thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,所以我想通了。在 webconfig 中,您需要设置“customerErrors”属性,否则它根本不起作用。最后,我想我应该在发布之前花更多的时间来研究它......
Okay, so I figured it out. In the webconfig you need to have the "customerErrors" property set or it won't work at all. In the end I guess I should have spent some more time working on it before posting...