Getting the ClaimsPrincipal in a logic layer in an aspnet core 1 application

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:

services.AddTransient<ClaimsPrincipal>(s =>
    s.GetService<IHttpContextAccessor>().HttpContext.User);

This feels kind of weird injecting it, however it is better than storing it in the CallContext.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)