How to get user id directly after login
I am wondering how I can get the user id right after validation. Is there any other way I can use to login than
FormsAuthentication.RedirectFromLoginPage (username, true);
Here's what I have.
if (Membership.ValidateUser(userName, password))
{
// i get a null object on the below as i haven't logged in yet
Guid UserID = new Guid(Membership.GetUser(User.Identity.Name).ProviderUserKey.ToString());
// some other logic that requires UserId
}
+2
a source to share
1 answer
If you haven't registered them yet, why not use the userName variable instead of the User object? You have already verified that this is a valid username.
if (Membership.ValidateUser(userName, password))
{
Guid UserID = new Guid(Membership.GetUser(userName).ProviderUserKey.ToString());
}
+1
a source to share