Skip to content

Instantly share code, notes, and snippets.

@gavilanch
Last active August 4, 2019 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gavilanch/085e481f61b224223492093165abd630 to your computer and use it in GitHub Desktop.
Save gavilanch/085e481f61b224223492093165abd630 to your computer and use it in GitHub Desktop.
public class CurrentUserService : ICurrentUserService
{
private readonly IHttpContextAccessor httpContextAccessor;
public CurrentUserService(IHttpContextAccessor httpContextAccessor)
{
this.httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor));
}
public string GetCurrentUsername()
{
return httpContextAccessor.HttpContext.User.Identity.Name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment