【问题标题】:WCF prevent debugger breaking at DataServiceExceptionWCF 防止调试器在 DataServiceException 处中断
【发布时间】:2013-02-20 06:53:41
【问题描述】:

我抛出未处理的 DataServiceExceptions(它们由 WCF 自动处理)以返回未授权访问的状态代码等。如何防止 Visual Studio 中断这些未处理的异常?

if (!System.Web.Security.Roles.IsUserInRole("Users"))
        {
            throw new DataServiceException((int)HttpStatusCode.Unauthorized, "You do not have access to this resource.");
        }

【问题讨论】:

  • “我使用未处理的 DataServiceExceptions”、“它们由 WCF 自动处理”、“在这些未处理的异常中中断”。所以基本上你正在处理它吗?你在 catch 声明中抓住它了吗?还是直接扔?
  • 请更新您的代码...
  • 我只是抛出新的 DataServiceException(401, "Error...")。 WCF 自动解包并将格式化的错误消息发送到客户端,但 Visual Studio 仍然在我的代码行中断。根本没有try..catch。

标签: asp.net wcf iis visual-studio-debugging


【解决方案1】:

能否添加一个 DebuggerNonUserCode 属性

或者您可以告诉 Visual Studio 忽略异常类型,如:How to tell the debugger to ignore breaking on thrown exceptions?

【讨论】:

  • 属性不能只应用于整个方法或类吗?如果前面或后面的行中还有另一个异常,我仍然希望它中断。
  • 编辑了我的答案 - 这有帮助吗?
猜你喜欢
  • 1970-01-01
  • 2023-03-12
  • 2013-11-19
  • 2015-06-30
  • 2010-11-25
  • 2011-07-14
  • 2013-09-27
  • 2015-07-17
  • 2015-02-08
相关资源
最近更新 更多