.net - ASP.NET Web API Exception filter - A way to get request url from HttpRequestBase? -


i've implemented custom exception filter web api. working intended, except 1 small detail...

in following code sample, savetoerrorlog saves exception details , tries request url context.request.rawurl. context.request not contain url api tried serve when exception happened. there way url when using exception filter this?

public class apiexceptionfilter : exceptionfilterattribute {     private httpcontextbase context;      public apiexceptionfilter()      {         context = new httpcontextwrapper(httpcontext.current);     }      public override void onexception(httpactionexecutedcontext actioncontext)     {         actioncontext.response = new httpresponsemessage(httpstatuscode.internalservererror);                if (actioncontext != null && context != null)         {             facade.savetoerrorlog(actioncontext.exception, context.request);         }               throw new httpresponseexception(new httpresponsemessage(httpstatuscode.internalservererror)         {                            content = new stringcontent(actioncontext.exception.message),             reasonphrase = "apiexception"         });     } } 

as per comment above @emre_nevayeshirazi, need use httpactionexecutedcontext. gives access request , required uri.

public override void onexception(httpactionexecutedcontext actionexecutedcontext) {     var requesteduri = actionexecutedcontext.request.requesturi;    //do } 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -