为什么 global.asax Application_Error 方法没有捕获 ASMX 服务抛出的异常? [英] Why global.asax Application_Error method does not catch exceptions thrown by ASMX service?

查看:21
本文介绍了为什么 global.asax Application_Error 方法没有捕获 ASMX 服务抛出的异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以及如何修复它.为了维护目的,我想记录每个抛出的异常.

And how to fix it. I'd like to log every thrown exception for maintenance purpose.

推荐答案

这是 .Net 中的一个已知问题 - Application_Error 从不为 Web 服务触发.不确定是否有任何原因是设计使然,但它就是行不通.

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 有一个帖子(和follow-up) 几年前关于这个,有以下想法:

Jeff Atwood had a post (and follow-up) about this a few years ago, with the following ideas:

  • 在每个 Web 服务方法周围放置一个 try-catch 块
  • 使用外观设计模式并将 try-catch 包含在父对象中
  • 编写自定义 SOAP 扩展或 HTTPModule

我唯一关心的是第一个,尽管它看起来工作量很大.

The only one I care for is the first one, even though it seems like a lot of work.

这篇关于为什么 global.asax Application_Error 方法没有捕获 ASMX 服务抛出的异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆