ASP.NET Membership Execution Login from codebehind in a click handler

I try to easily log in without prompting for credentials as part of the <asp:Wizard> process. My strategy is to handle the NextButtonClick event and inject the user into the code. I already have user credentials stored in session variables.

Is it possible to log in a user in code? Will there be a hidden <asp:Login> control behind the scenes?

+4
source share
3 answers

If you save your credentials in a session, I hope you encrypt them.

But yes, if you already have your credentials, you can do:

 FormsAuthentication.SetAuthCookie(username, true); 

You can also run:

 if(Membership.ValidateUser(username, password)) { FormsAuthentication.SetAuthCookie(username, true); } 

to make sure you have the correct username and password.

+7
source
 // This will redirect the user (check Jack Marchetti answer for other option) FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, false); 

This will issue an authentication ticket to the user.

+2
source

If you are using FormsAuthentication, then just create a session cookie:

 // pass true to create a persistent cookie FormsAuthentication.SetAuthCookie("userNameHere", true); 
+1
source

All Articles