In ASP.net 2.0, the newly added membership provider feature, together with a powerful series of registrations, login controls, can easily manage user login and permissions (see <<asp.net 2.0 Login Control profile > >).
However, you may find that the management features of these login controls and membership, which are ASP.net 2.0, are used by default with SQL Server Express, so how to change to use SQL Server 2000 or other data sources, such as access,oracle and so on? If you want to be in the application, another to write a login user or user rights and other management applications, how to modify it? In this article, you will be given a simple landing process that uses a custom provider in ASP.net 2.0 to match the login control.
To understand how the provider in asp.net 2.0 works, first look at the following structure:
As you can see from the above picture, at the top level, there are various landing controls, and the following layer is the membership API associated with member. In the membership API, the membership class performs actions on the user, such as adding and deleting users, while the MembershipUser class stores information about the user's personal information, such as user name, password, email, and so on.
In Visual Studio 2, the default is SQL Express membership provider. Provider's role is to communicate membership API and database, so that users do not need to care about what kind of database to use, all operations can be implemented with various types of data provider.
But most of the time, ASP.net 2.0 default support provider is not enough to meet their needs, we can write their own provider. In this article, you will find out how to use an Access database to create a datasheet that holds the user's information. The methods described in this article can also be applied to other databases.
First, we open Visual Studio 2, select VB.net, and create a new Web site. In this example, for the sake of simplicity, we set up a user registration form, a login form, the new user can register first, and then log in.
Next, in the default form, drag and drop a CreateUserWizard control, a system-supplied automatic control for new users, which makes it easy to create a new user. To make the page beautiful, we click "IntelliSense" at the top right of the control, select "Auto Format", and then select "Elegant" style in the pop-up form, as shown in the following figure:
Of course, we can modify the text hints of the control arbitrarily. Here we want to enable users to go to the landing page after registration, so set the control's Continuedestinationpageurl property value is: Login.aspx, this page will be written.
Next, drag a LoginView control into the Default.aspx page. In the control, can set two kinds of templates: Anonymous template, said the user did not log in before the status of visitors to see; LoggedIn template, said that the user after the successful landing, see the state (here can be set some text display, such as Welcome to enter, and generally will display the user's name).
Here, in the Loggedin template in the LoginView control, we enter "You are logged in" and add a loginname and a LoginStatus control. Where the LoginName control displays the ID of the user after the login, and the LoginStatus control, a link to the logout (logoff) is displayed when the user logs on. As shown in the following two figure: