I am trying to figure out how to get access to the current logged in username outside of an ASP.NET Controller.
For example I am trying to do this:
Track Created and Modified fields Automatically with Entity Framework Code First
To setup tracking on entities in the DbContext
.
Here is my ApplicationDbContext
but I keep getting an error saying _httpContextAccessor
is null
:
private readonly IHttpContextAccessor _httpContextAccessor;
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options, IHttpContextAccessor httpContextAccessor)
: base(options)
{
_httpContextAccessor = httpContextAccessor;
}