ASPNET Login Controls
Earlier in this chapter, you handcrafted a couple of different login pages . During the heyday of ASP.NET 1 .1, that's exactly what you had to do to get Forms Authentication to work . Later versions of ASP.NET add a number of login controls that perform the most common login scenarios you might need for your site .
These controls include the Login, LoginView, PasswordRecovery, LoginStatus, LoginName, ChangePassword, and CreateUserWizard controls . Here's a summary of what each control does:
■ Login The Login control is the simplest login control and supports the most common login scenario—signing in using a user name and password. The control includes user name and password text boxes and a check box for users who want to compromise password security by saving their passwords on the computer. The control exposes properties through which you can change its text and appearance . You can also add links to manage registration and password recovery. The Login control interacts with the ASP.NET membership component for authentication by default . If you want to manage authentication yourself, you can do so by handling the control's Authenticate event
■ LoginView The LoginView control is very similar to the optional login page discussed earlier. It's useful for managing the content you display for authenticated versus unau-thenticated users. The LoginView displays the login status through the display templates AnonymousTemplate and LoggedInTemplate. The control renders a different template depending on the status of the user. With the LoginView control, you can also manage text and links in each template
■ PasswordRecovery The PasswordRecovery control supports Web sites that send user passwords to clients when users forget their passwords The control collects the user's account name and then follows up with a security question (provided that functionality is set up correctly) . The control either e-mails the current password to the user or creates a new one
■ LoginStatus The LoginStatus control displays whether the current user is logged on . Users who are not logged in are prompted to log in, whereas logged-in users are prompted to log out
■ LoginName The LoginName control displays the user's login name.
■ ChangePassword The ChangePassword control gives users a chance to change their passwords . An authenticated user can change his or her password by supplying the original password and a new password along with a confirmation of the new password.
■ CreateUserWizard The CreateUserWizard control collects information from users so that it can set up an ASP.NET membership account for them. Out of the box, the control gathers a user name, a password, an e-mail address, a security question, and a security answer. The CreateUserWizard can collect different information from users depending on the membership provider your application uses.
The following exercise illustrates how to write a login page using the login controls .
Post a comment