2013-02-20 13 views
0

我拋出未處理的DataServiceExceptions(它們由WCF自動處理)返回未授權訪問的狀態代碼等。如何防止Visual Studio在這些未處理的異常中斷?WCF阻止調試器在DataServiceException中破壞

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

「我用未處理DataServiceExceptions」,「他們是由WCF自動處理「,」打破這些未處理的例外「。所以基本上你正在處理它呢?你是否抓住了聲明?或只是扔它? – 2013-02-20 07:08:02

+0

請更新您的代碼... – 2013-02-20 07:28:55

+0

我只是拋出新的DataServiceException(401,「錯誤...」)。 WCF自動解包並將格式化的錯誤消息發送給客戶端,但Visual Studio仍在我的代碼中斷行。根本沒有try..catch。 – Monstieur 2013-02-20 07:42:16

回答

0

你可以添加一個DebuggerNonUserCode屬性

,或者你可以告訴Visual Studio中忽略了的異常類型,如:How to tell the debugger to ignore breaking on thrown exceptions?

+0

不能只將屬性應用於整個方法或類嗎?如果在上一行或下一行中有另一個異常,我仍然希望它中斷。 – Monstieur 2013-02-20 08:38:36

+0

編輯我的答案 - 這有幫助嗎? – 2013-02-20 08:58:02