I'm currently working on an ASP.NET Core 5 MVC web project, I used default created Single User Account generated template for user management. I have applied the migration and it's working fine as expected. I need to get logged user, in .NET 5 Single User Account template AccountController
was not visible. I tried following code outside the controller, it's giving null
.
public class UserService
{
private readonly IHttpContextAccessor _context;
public UserService(IHttpContextAccessor context)
{
_context = context;
}
public string GetUser()
{
return _context.HttpContext.User?.Identity?.Name;
}
}