I have an MVC Web Api project and I am logging all requests and responses with MessageHandler. When an api request arrives, the carrier token in the header allows Asp.Net to do its job and authenticate that user. Therefore, the message handler knows who the user is, and we write it to the log file.
Now, to speed things up, I cache using Cachecow. Therefore, I added the cachecow handler after MessageHandler, and when the second request arrives, everything works fine from the cache point. The controller code never hits and the response is returned from the cache.
However, MessageHandler does not matter for User.Identity, so I cannot say who made the request.
I need to register all requests and determine who made them, even if the code did not get into the controllers.
I think one workaround is to force api requests to pass the carrier token and user id in the header. That way, I can check the user id request and use it to register who made the 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 authentication is zero when receiving a response from the 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?