Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I manually log a user in with a MembershipProvider?

I'm experimenting with writing my own custom MembershipProvider in asp.net and I want to roll my own login page. We do some fairly special stuff at login time so we can't use the default login control so I need a way to manually log a user in.

So far I haven't found anything on how to write your own login control so I'm here, wondering how I can manually log a user in via a MembershipProvider.

I've tried

Membership.ValidateUser("user", "pass");

and while that does call ValidateUser() on my custom MembershipProvider, and it does return true, it doesn't actually log me in.

Btw I'm fairly new to the whole MembershipProvider stuff so if I'm not even on the right wavelength, feel free to let me know.

like image 501
Allen Rice Avatar asked Dec 01 '22 10:12

Allen Rice


1 Answers

if (Membership.ValidateUser(Username.Text, Password.Text))
{

   FormsAuthentication.SetAuthCookie(Username.Text, false);
   FormsAuthentication.RedirectFromLoginPage(Username.Text, false);
}
else
{
// do something else
}

The above was copied from working code with a custom membership provider in a situation just like yours, where we needed to do a bunch of extra work at login. (Sensitive operations reomved to protect the innocent.)

like image 80
David Avatar answered Dec 05 '22 01:12

David