Last post Dec 31, 2015 05:35 AM by Candice Zhou
Dec 30, 2015 05:02 PM|brucey|LINK
I need some help here, I am trying to identify a user after they have logged in. My code works ok apart from the where clause. How do you identify a user,
I am basically trying to say where UserName == loginName give me the full record. Then from the record I can pull out the GarageID, any help or pointers much appreciated.
private void FindGarageID()
System.Security.Principal.WindowsIdentity identity = Context.Request.LogonUserIdentity;
string loginName = identity.Name;
using (tyrescannerdatabaseEntities dbcontext = new tyrescannerdatabaseEntities())
garage = (from r in dbcontext.AspNetUsers
where r.UserName == loginName
garageID = (int)garage.GarageID;
garageID = 1;
Dec 31, 2015 05:35 AM|Candice Zhou|LINK
Inside the AccountController you can call the following method to get user object and then get the User Id.
var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());
FindById requires you have the following using statement so that the non-async UserManager methods are available.
For more information, please refer to this thread: