I'm trying to get the current user ID so my Events index page will show events from only current user.
my HttpContext.User has the error "Cannot convert from System.security.claims.claimsPrincipal to Scheduler.Areas.Identity.Data" inside the index of my Events controller.
var userId = await _userManager.GetUserIdAsync(HttpContext.User);
Here is the code in my EventsController:
public EventsController(SchedulerDbContext context, UserManager<SchedulerUser> userManager)
{
_context = context;
_userManager = userManager;
}
// GET: Events
[Authorize]
public async Task<IActionResult> Index()
{
var userId = await _userManager.GetUserIdAsync(HttpContext.User);
return View(await _context.Events.Where(g => g.SchedulerUser == userId).ToListAsync());
}
Where should I be looking to solve this? I'll update with more code if required.