I'm writing an aspnet core 1 application.
Using a bearer token authentication I have the User property inside the controller with the correct identity. However I cant seem to find a way to grab with identity as I did before using the ClaimPrincipal.Current
static.
What is the current best practice to get this data inside the BL layers with out passing the ClaimPrincipal object around?
相关问题
- Carriage Return (ASCII chr 13) is missing from tex
- Generic Generics in Managed C++
- How to store image outside of the website's ro
- How to Debug/Register a Permanent WMI Event Which
- 'System.Threading.ThreadAbortException' in
Here is better answer for dotnet core 2.0 and newer: https://adamstorr.azurewebsites.net/blog/are-you-registering-ihttpcontextaccessor-correctly
Basically add IHttpContextAccessor to services as Singleton:
To consume inject IHttpContextAccessor into your class:
and access _httpContextAccessor.HttpContext in your methods.
Further investigating this issue I've found that it is possible to use the native DI container to inject the
ClaimsPrincipal
where needed like that:This feels kind of weird injecting it, however it is better than storing it in the
CallContext
.