Thursday, March 29, 2012

Login Controls

Hi

I'm using the login controls, and all is good except for the fact that i will be storing personal info on users in a diff table, so
i need to pass the UserID and be able to use the UserID of the logged in user to get the correct data on them.

so how do i get the userID, and where do i execute code to get the UserID and store it in a session var or something?

Thanks
Shem

Hi there

You can do all this within the OnAuthenticate method:

publicvoid OnAuthenticate(object sender,AuthenticateEventArgs e)
{
bool Authenticated =false;
Authenticated = AuthenticateUser(lgLogin.UserName, lgLogin.Password);
if (Authenticated)
{
FormsAuthentication.RedirectFromLoginPage(lgLogin.UserName,false);
}
else
{
// do something else
}
}

Within this method pass the login details into another method. This second method can use the username to retrieve the userid and whatever other information, authenticate the user (checking it exists in database etc) and set some user information in session variables. After it does all this the second method returns a value of true, allowing the redirect from the login page.

Hope this helps.

0 comments:

Post a Comment