1

I've a DelegatingHandler in my Web-API service that, based on the headers provided, set a custom IPrincipal (ServicePrincipal) on the Thread.CurrentPrincipal and on the HttpContext.Current.User. This is all done on a call to SendAsync.

However, when the call get's into the Controller, the User property, the HttpContext.User and the Thread.CurrentPrincipal have all been mysteriously set to a RolePrincipal.

Does anyone know either what I'm doing wrong, or how to prevent the additional principal being set?

Thanks,
Kieron

Kieron
  • 26,748
  • 16
  • 78
  • 122

1 Answers1

3

I know this question is old, but I was having a similar issue trying to get the current user from within a function overriding DelegatingHandler.SendAsync(). The IPrincipal object doesn't seem to get initialized until after the call to base.SendAsync(). After that line is called, the IPrincipal object should have the user information.

I used request.GetRequestContext().Principal to retrieve it, but I'm guessing Thread.CurrentPrincipal would work too.

Evan
  • 836
  • 1
  • 13
  • 25