asp.net web api - Exception in ExceptionFilterAttribute is always of type HttpResponseException -
following this post on exception handling in asp.net web api, created exceptionfilterattribute
looks this:
public class notimplexceptionfilterattribute : exceptionfilterattribute { public override void onexception(httpactionexecutedcontext context) { if (context.exception notimplementedexception) { context.response = new httpresponsemessage(httpstatuscode.notimplemented); } } }
... , asp.net web api controller looks this:
public class productscontroller : apicontroller { [notimplexceptionfilter] public string get() { throw new notimplementedexception("this method not implemented"); } }
the problem context.exception
always of type system.web.http.httpresponseexception
no matter exception throw in actionmethod
. such, code inside if
statement never gets executed. message
property on exception is:
processing of http request resulted in exception. please see http response returned 'response' property of exception details.
the response
property referenced in message 500 internal server error
.
my routes configured correctly because actionmethod
hit. don't have other exceptionfilterattribute
filters applied.
any idea how can context.exception
reference exception thrown?
Comments
Post a Comment