views:

57

answers:

1

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, 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


        }
+1  A: 

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());
}
Brandon