J
Jonathan Wood
I'm writing code to log in a user without using the standard Login control.
The following code seems to do the trick.
if (Membership.ValidateUser(txtUserName.Text, txtPassword.Text))
FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, true);
But I don't get why.
Membership.ValidateUser() tells me if the credentials are valid but appears
not to actually log the user in.
FormsAuthentication.RedirectFromLoginPage() appears that it DOES log the
user in. But the docs don't seem to say anything about that:
"The RedirectFromLoginPage method redirects to the URL specified in the
query string using the ReturnURL variable name. For example, in the URL
http://www.contoso.com/login.aspx?ReturnUrl=caller.aspx, the
RedirectFromLoginPage method redirects tothe return URL caller.aspx. If the
ReturnURL variable does not exist, the RedirectFromLoginPage method
redirects to the URL in the DefaultUrl property."
My question is: Does anyone know if this is the "preferred" way to log in a
user without using the Login control. And if RedirectFromLoginPage logs a
user in, does anyone know why this wasn't documented?
Thanks.
The following code seems to do the trick.
if (Membership.ValidateUser(txtUserName.Text, txtPassword.Text))
FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, true);
But I don't get why.
Membership.ValidateUser() tells me if the credentials are valid but appears
not to actually log the user in.
FormsAuthentication.RedirectFromLoginPage() appears that it DOES log the
user in. But the docs don't seem to say anything about that:
"The RedirectFromLoginPage method redirects to the URL specified in the
query string using the ReturnURL variable name. For example, in the URL
http://www.contoso.com/login.aspx?ReturnUrl=caller.aspx, the
RedirectFromLoginPage method redirects tothe return URL caller.aspx. If the
ReturnURL variable does not exist, the RedirectFromLoginPage method
redirects to the URL in the DefaultUrl property."
My question is: Does anyone know if this is the "preferred" way to log in a
user without using the Login control. And if RedirectFromLoginPage logs a
user in, does anyone know why this wasn't documented?
Thanks.