ClaimsPrincipal in ASP.Net core MVC web app

ClaimsPrincipal in ASP.Net core MVC web app

In this article, ClaimsPrincipal.Current isn't set in ASP.NET Core. So, it uses dependency injection to provide dependencies such as the current user's identity.

There are several options for retrieving the current authenticated user's ClaimsPrincipal:

  • ControllerBase.User (MVC controller).
  • Passed in from caller (libraries without access to HttpContext).
  • IHttpContextAccessor (when passing around the user's identity too much).
  • HttpContext.User (middleware).

2020-08-24