C
C#3w ago
Akama Aka

ASP.NET Identity, get User ID on POST Request

Hello, I'm currently learning ASP.NET Identity and would like to make a Recomendations Website. Currently I've a Model File which has a userID datafield which has a Foreign Key to the IdentityUser.Id. Now my question is how can I add the Current Logged In User ID into this field without any Security Problems? I coul'dnt really find anything on google and if then just things that doesnt work or exist anymore.
1 Reply
Pobiega
Pobiega3w ago
In any ASP controller, you can access the HttpContext.User property to see what is known about the current logged in user That property in turn has a few interesting properties, like Identity, Claims and Identities use the debugger to inspect those for a logged in user, and you'll probably find something you can use to look up the userid alternatively, change your login method to register a claim with the userid

Did you find this page helpful?