-----------------------------------------------------------
New Message on MumbaiUserGroup
-----------------------------------------------------------
From: Swapnil_B1
Message 1 in Discussion
Membership Providers
A membership provider is the glue between the Login control and the membership
database. The login control doesn't care if the membership provider is a custom
provider or a Microsoft provider. The login control knows which provider to
instantiate based on entries in the web.config file. The custom provider acts
just like the Microsoft-supplied providers because it inherits from and
overrides the MembershipProvider class.
Membership Providers provide the interface between the Membership services and
membership data sources. The Two common reasons for writing a custom membership
provider are:
You wish to store membership information in data source that is support by the
membership providers included in .Net framework, such as an Oracle database or
Web service.
You wish to store the membership information in the SQL server database whose
schema differs from that of the database used by
System.Web.Security.SQLMembershipProvider if you integrate membership service
with existing membership database.
The fundamental job of a membership provider is to interface with data sources
containing data regarding a sites registered users, to provide methods for
creating users, deleting users, verifying login credentials, changing passwords
and so on. The .NET Framework's System.Web.Security namespace includes a class
named MembershipUser that defines the basic attributes of a membership user and
that a membership provider uses to represent individual users.
Steps Involved when Using a Custom Provider with the Login Control
There are three main steps required to use a custom provider with the Login
control.
· The login control needs to be placed on a aspx page (login.aspx).
· The custom provider class needs to inherit from MembershipProvider
and override certain methods.
· The web.config file needs to be modified to use a custom provider.
How the Login Control Works
The Login control provides two textboxes for a User Email and a User Password,
along with a submit button. Once the user provides this information and clicks
on the submit button, the custom membership provider class is called to
authenticate the user. Once the user has been authenticated, the
Context.User.Identity.IsAuthenticated property is set to true. The login
control's DestinationPageURL property tells the web site where to direct the
user if the validation is successful.
MyCustomMembershipProvider : MembershipProvider
This class is called from the login control for validation of the user's email
and user's password. This class has several properties and methods that are
required to make the glue between the Login control and your custom provider
due the the inheritance from MembershipProvider. You will see in
MyCustomMembershipProvider that they are provided but throw "not implemented"
exceptions.
The two important methods in MyCustomMembershipProvider for the the custom
provider are Initialize, and ValidateUser. Initialize is another place besides
the web.config file to set properties for your custom provider. ValidateUser is
the main function for the Login control to validate the user and password.
public override bool ValidateUser(string strName, string strPassword)
{
//This is the custom function you need to write. It can do anything you
want.
//The code below is just one example.
// strName is really an email address in this implementation
bool boolReturn = false;
// Here is your custom user object connecting to your custom membership
database
MyUserProvider oUserProvider = new MyUserProvider();
MyUser oUser = oUserProvider.FindUser(strName);
if (oUser == null)
return boolReturn;
// Here is your custom validation of the user and password
boolReturn = oUser.ValidateUsersPasswordForLogon(strPassword);
return boolReturn;
}
ValidateUser takes two parameters which are the Name and Password of the user.
For many web sites, the Name will be the User's email address. The method
returns true or false depending on the results of this validation. All the code
inside the method is up to you to provide. The code provided in this above
example is just one possibility.
Successful Validation with the Login Control
Upon successful validation, the Login control will redirect to the page
referenced in the DestinationPageURL property, let's call this page hello.aspx.
This valid user is now in a context variable and can be retrieved with the
Context.User.Identity property.
Failed Validation with the Login Control
The login control has many properties, methods, and events to manage the look
and feel of the control both on the first instance of the page as well as post
back. A default failure message is provided and will appear on the Login
control if validation is unsuccessful.
Swapnil (Swaps)
http://swapsnet.spaces.live.com/
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/MumbaiUserGroup/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you
received this message by mistake, please click the "Remove" link below. On the
pre-addressed e-mail message that opens, simply click "Send". Your e-mail
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]