How to get userid directly after login in
I'm wonder how i can get the userid just after i validate. Is there another method i can use to login than
FormsAuthentication.RedirectFromLoginPage(userName, true);
Here's what i have.
if (Membership.ValidateUser(userName,开发者_StackOverflow社区 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
}
If you haven't logged them in yet, why not use the userName variable instead of the User object? You've already verified it is a valid username.
if (Membership.ValidateUser(userName, password))
{
Guid UserID = new Guid(Membership.GetUser(userName).ProviderUserKey.ToString());
}
精彩评论