2013-03-25 43 views
0

當我嘗試從我的控制器拋出以下禁止的ResponseException。一個異常說明「處理HTTP請求導致異常,請參閱此異常的」響應「屬性返回的HTTP響應以獲取詳細信息。」捕獲在控制器方法的catch塊中。需要幫助解決這個無法拋出httpResponseException

throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)); 
+0

你在哪裏拋出異常? – 2013-03-25 04:57:25

+0

我從模型類中拋出這個異常 – Mohan 2013-03-25 05:07:58

回答

0

只要改變你的控制器實現,如果它是一個HttpResponseException重新拋出:

try 
{ 
    // action implementation 
} 
catch (Exception e) 
{ 
    if (e is HttpResponseException) 
    { 
     throw e; 
    } 
    // error handling logic 
} 

但更好的答案是,#1 - 你應該避免被捕獲所有異常,這是不好的做法。而#2 - 您應該使用異常過濾器來進行錯誤處理,而不是自己捕捉異常。