문제

When I try to throw the below forbidden ResponseException from my controller. An exception stating "Processing of the HTTP request resulted in an exception. Please see the HTTP response returned by the 'Response' property of this exception for details." is catched in the catch block of the controller method. Need help in resolving this

throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
도움이 되었습니까?

해결책

Just change your controller implementation to re-throw if it's an HttpResponseException:

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

But the better answer is that #1 - you should avoid be catching all exceptions, that's bad practice. And #2 - you should use an exception filter instead to do your error handling and not catch exceptions yourself.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top