Introduction to landing controls in asp.net 2.0 (3)

Source: Internet
Author: User
Tags mail
Asp.net| Control CreateUserWizard Control

With this control, you can easily guide the user to sign up in a step-by-step manner. Drag it to the design form, as shown in the following figure:


Of course, you can set more of its properties, such as setting HeaderTemplate (header Template), Startnavigationtemplate (start registration template), Finishnavigationtemplate (end registration template), etc., Specific settings can refer to online Help. The control also allows you to send a message to a user after a successful registration, such as:

<asp:createuserwizard id= "CreateUserWizard1" runat= "Server"
<maildefinition
Bodyfilename= "NewUserEmail.txt"
From= "Welcome@dorknozzle.com"
Subject= "Welcome to the Dorknozzle site!" />
</asp:CreateUserWizard>

Sending a message requires you to configure it in the Web.config file, such as:

<configuration>
<system.web>
<authentication mode= "Forms"/>
<smtpmail servername= "Localhost"/>
</system.web>
</configuration>

PasswordRecovery Password Recovery control

The control can implement a simple password prompt recovery function and email the password to the user with the following code:

<asp:passwordrecovery id= "Prforgotpass" runat= "Server" > </asp:PasswordRecovery>

The implementation is shown in the following illustration:



The user enters the user name, then needs to enter the password recovery The answer, the following figure:

And in the control, set the restored password to email to the user

<asp:passwordrecovery id= "Prforgotpass" runat= "Server"
<maildefinition
Bodyfilename= "Forgotpassword.txt"
From= "Helpdesk@dorknozzle.com"
Subject= "Word has it, you forgot your password?" />
</asp:PasswordRecovery>

ChangePassword Change Password control

Changing the password control makes it easy to implement password changes, including a MailDefinition property. If you assign a value to the MailDefinition property, the ChangePassword control automatically sends an e-mail message to the user when the password is successfully changed.


Direct use of the membership API

Sometimes, you need to have a higher level of membership (than the control level provided by the WEB Site Administration tool or Login control). In these cases, you can use the membership API directly.

The membership API is exposed through the membership class. The Membership class contains methods that enable you to create new users, change passwords, search for users who match specific criteria, and so on. Behind the scenes, the Login control uses these methods to interact with the configured membership provider.

Some of the more important methods of the membership class are listed below:

Createuser-enables you to create new users.

deleteuser-enables you to delete existing users.

Findusersbyemail-enables you to retrieve a collection of users that match a particular e-mail address.

Findusersbyname-enables you to retrieve a collection of users that match a particular user name.

Generatepassword-allows you to generate random passwords.

Getallusers-enables you to retrieve all users stored in a membership provider.

Getnumberofusersonline-enables you to return the number of users who are currently accessing the WEB application.

Getuser-enables you to retrieve the membership information associated with the current user, or to enable you to retrieve the membership information associated with a user who has provided a user name.

Getusernamebyemail-enables you to retrieve the user name of a user with a specific e-mail address.

updateuser-enables you to update information for a specific user.

Validateuser-enables you to authenticate users based on the membership provider.

Finally, we use the API to implement a slightly more complex function. In Index.aspx, add a Label control that displays the number of people online, and the code is as follows:

Number of Users Online:
<asp:label id= "Lblnumusersonline" runat= "Server"/>

In the Page-load event, add the following code:

Sub Page_Load (S as Object, E as EventArgs) Handles MyBase.Load
Lblnumusersonline.text = _
Membership.getnumberofusersonline (). ToString ()
End Sub

You can display the number of people online. We also add a GridView that shows the online status of all users, whether certain permissions and related information are allowed.

<asp:gridview id= "gvusers" runat= "Server" autogeneratecolumns= "False"
<Columns>
<asp:boundfield headertext= "Username" datafield= "Username"
<asp:boundfield headertext= "is Online?" Datafield= "Isonline"/>
<asp:boundfield headertext= "is Approved?" Datafield= "isapproved"/>
<asp:boundfield headertext= "Email" datafield= "email"
</Columns>
</asp:GridView>

And bind the GridView:

Gvusers.datasource = Membership.getallusers ();
Gvusers.databind ();

The results of the final operation are shown below:

Summarize:

This article presents a practical example of the simple usage of the newly added login-series control in ASP.net 2.0 and the simple use of the newly added membership API, for more information on the MSDN or official version.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.