bassem ala
bassem ala

Reputation: 191

automatically authenticate user using c# membership provider

I am using c# membership provider and I get the username from a query string. Now I need to check if the username exist if it does I need to automatically authenticate the user.

How do I check if the user exists in the membership database?

Upvotes: 0

Views: 2340

Answers (3)

ComWizd
ComWizd

Reputation: 300

If you have a password:

 if (Membership.ValidateUser(userName, "password")) 
 {
     FormsAuthentication.SetAuthCookie(userName, true);
     Response.Redirect("~/welcome.aspx");
 }

or if you just want to check if the user exist and log them in

 if (Membership.GetUser(userName) != null) 
 { 
     FormsAuthentication.SetAuthCookie(userName, true); 
     Response.Redirect("~/welcome.aspx");
 }

Upvotes: 2

PraveenVenu
PraveenVenu

Reputation: 8337

If you are looking for an SSO solution, you can find more information here

http://weblogs.asp.net/hernandl/archive/2004/06/09/ssoformsauth.aspx

Upvotes: 1

Tuan
Tuan

Reputation: 5412

Check the Membership.GetUser method. If the user exists, you can then use FormsAuthentication.SetAuthCookie to authenticate the user.

Upvotes: 1

Related Questions