In the last post I talked about How to get current user in ASP.Net MVC 5 . Type of the current user is IPrincipal which is shown as follows:
You may come across requirement to work with ApplicationUser which is created as follows:
You can covert returned User to ApplicationUser as follows:
ApplicationDbContext db = new ApplicationDbContext(); ApplicationUser appUser = db.Users.FirstOrDefault(x => x.Id == userId); return appUser ;
To convert create instance of the ApplicationDBContext and then fetch user using LINQ to Entity. Returned user from context is of type ApplicationUser.
Hope it helps. Happy coding.
Leave a Reply