c# - Web API global error handling add custom header in response -
i wondering if possible set custom header values whenever internal server error has occurred? doing:
public class fooexceptionhandler : exceptionhandler { public override void handle(exceptionhandlercontext context) { // context.result contains custom header values context.result = new internalservererrorresult(context.request); } }
here want set header values though appears in request response not contain it.
is there way of doing this?
it should possible creating own exception filter.
namespace myapplication.filters { using system; using system.net; using system.net.http; using system.web.http.filters; public class customheadersfilterattribute : exceptionfilterattribute { public override void onexception(httpactionexecutedcontext context) { context.response.content.headers.add("x-customheader", "whatever..."); } }
}
http://www.asp.net/web-api/overview/error-handling/exception-handling
Comments
Post a Comment