asp.net - Getting User Id in Web Api handler when using Cachecow -


i have mvc web api project , logging requests , responses using messagehandler. when api request comes in, bearer token in header lets asp.net thing , authenticates user. message handler therefore knows user , write log file.

now, speed things i'm caching cachecow. i've added cachecow handler after messagehandler , when second request comes in, caching point of view works fine. controller code never hit , response returned cache.

however, messagehandler not have value user.identity cannot tell made request.

i need log requests , identify made them when code in controllers not hit.

i think 1 workaround force api requests pass bearer token , user id in header. way can check user id claim , use log made request.

protected override async task outgoingmessageasync(string correlationid, string requestinfo, byte[] message, string responsetimemilliseconds)         {             await task.run(() =>                 debug.writeline(string.format("{0} - response: {1}\r\n{2}", correlationid, requestinfo, encoding.utf8.getstring(message))));                      );         } 

user identity null when getting response cache.

?httpcontext.current.user.identity {system.security.claims.claimsidentity}     [system.security.claims.claimsidentity]: {system.security.claims.claimsidentity}     authenticationtype: null     isauthenticated: false     name: null 

any ideas?

try in

system.threading.thread.currentprincipal


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -