为什么 global.asax Application_Error 方法不能捕获 ASMX 服务抛出的异常?
以及如何解决它。 我想记录每个抛出的异常以用于维护目的。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
以及如何解决它。 我想记录每个抛出的异常以用于维护目的。
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
这是 .Net 中的一个已知问题 - Web 服务永远不会触发 Application_Error。 不确定是否有任何原因是设计使然,但它就是行不通。
杰夫·阿特伍德 (Jeff Atwood) 发表了一篇帖子(以及 follow-up) 几年前关于这个问题,有以下想法
我唯一关心的是第一个,尽管它看起来像很多工作。
This is a known issue in .Net - Application_Error never fires for a web service. Not sure if there's any reason it would be by design, but it just doesn't work.
Jeff Atwood had a post (and follow-up) about this a few years ago, with the following ideas:
The only one I care for is the first one, even though it seems like a lot of work.
更好: HttpApplication.Error 事件:
注意:
Better: HttpApplication.Error event:
Note:
对于任何寻找 Microsoft 关于此主题的信息的人,请参阅此处:“处理和抛出 XML Web 服务中的异常”。
这是相关部分:
For anyone looking for Microsoft's word on this topic, see here: "Handling and Throwing Exceptions in XML Web Services".
This is the relevant section: