ASP.NET provides user with login controls in the Login tab of the toolbox of the Visual Studio application. The following controls are provided to the user. Login Control The LoginView Control The LoginStatus Control LoginName Control PasswordRecovery Control CreateUserWizard Control ChangePassword Control 1. Login Control The login control provides a user interface for managing the authentication of users in a website. The authentication is performed on the basis of username and password. The page acess can be restricted by the use of the login controls. The Login class contains various methods, properties, and events to work with. Some of them are as listed below: CreateChildControls: It creates an individual control of the Login control and the event handlers are associated with it. OnLoggingIn: It raises the LoggingIn event when the user adds the login data before the authentication is completed. OnLoggedIn: It raises an LoggedIn event when the user log into the web site after the authentication is completed OnAuthenticate: It raises an Authenticate event for the user authentication. Properties of the Login Control CreateUserIconUrl: It retrieves the location of the image to display the link to the user. CreateUserUrl: It specifies or retrieves the URL for the new user page. DisplayRememberMe: It specifies the value stating whether to display the RememberMe checkbox. FailureText: It displays the text when the login attempt fails HelpPageText: It specifies the text of link to the login help page. Password: It retrieves the password entered by the user Events of the Login Control LoggedIn: It is initiated when the user logs in the web site and is authenticated. LoggingIn: It is initiated when the user submits the login information. LoginError: It is initiated when a login error is detected. The Login control at the design time is as shown below: 2. The LoginView Control The LoginView control is a web server control used for displaying the two different views of a web page. It helps to alter the page view for different logged in users. The current users status information is stored in the control. The control displays appropriate information depending on the user. The LoginView class provides the LoginView control. The methods, properties and events provided by the login class are as listed below: Methods of the LoginView class DataBind: It helps user to bind the data source through the LoginView control. OnViewChanged: It raises the ViewChanged event after the view for the control is changed. OnViewChanging: It raises the ViewChanging event before the LoginView control changes the view. Properties of the LoginView class Controls: It accesses the ControlCollection object containing the child controls for the LoginView control EnableTheming: It access or specifies the value indicating the themes to be applied to the control RoleGroups: It access the collection of role groups associated with the content templates Events of the LoginView class ViewChanged: It is initiated when the view is changed ViewChanging: It is initiated when the view is in the process to be changed. The LoginView control at the design time is as shown below: 3. The LoginStatus Control It specifies that a particular user has logged into the web site. The login status is displayed as a text. The login text is displayed as a hyperlink but provides the navigation to the login page. The authentication section of the web.config file is useful for accessing the login page URL. The LoggedIn and LoggedOut are the rwo status provided by the LoginStatus control. TheLoginStatus class provides the control. The methods, properties and events for the control are as mentioned below: Methods of the LoginStatus Control OnLoggedOut: It raises the event when the logout link is clicked by the user. OnLoggingOut: It raises the event when the user clicks the logout link of the control. Properties of the LoginStatus Control LoginImageUrl: It accesses or specifies the URL of the image used for the login link. LoginText: It access the text added for the login link LogoutAction: It retrieves the value for determining the action when the user logs out of the web site. LogoutText: It retrieves the text used for logout the link Events of the LoginStatus Control LogginOut: It is initiated when the user sends the logout request to the server. LoggedOut: It is initiated by the LoginStatus class when the user logout process is completed The LoginStatus control at the design time is as shown below: 4. LoginName Control It is used for displaying the name of the authenticated users. The Page.User.Identity.Name is used for returning the user name. The control is not displayed if it does not contain any logged in user. The LoginName class is used for the control. The control does not contain any method, property or events associated with it. The FormatString property is used for displaying the string in the control. The LoginName control at the design time is as shown below: 5. PasswordRecovery Control It is used to recover or reset the password for the user. The password is sent through an email as a message at the registration time. The Membership service is used for creating and resetting the password. The control contains the following three views. Question: It refers the view where the user can enter the answer to the security question. UserName: It refers to the view where the user can enter the username for the password to be recovered. Success: It represents the view where the message is displayed to the user. The control contains various properties, methods and events as mentioned below: Methods of the PasswordRecovery Control OnSendingMail: It raises the SendingMail event when the user is verified and the password is sent to the user. OnUserLookupErrror: It raises the UserLookupError when the username does not match with the one stored in the database, OnSendMailError: It raises an error when the mail message is not sent to the user. OnVerifyingUser: It raises the event once the username is submitted, and the membership provider verification is pending. Properties of the control Answer: The answer provided by the user to confirm the password recovery through the valid user FailureTextStyle: It accesses the reference to the collection of properties defining the error text look HelpPageIconUrl: It image to be displayed for the link to the password is retrieved Events of the control SendingMail: It is initiated when the server is sending an email message containing the password once the answer is correct AnswerLookupError: It is initiated when the user answer to the question is incorrect VerifyingAnswer: It is initiated when the user has submitted the answer to the password recovery confirmation question The PasswordRecovery control at the design time is as shown below: 6. CreateUserWizard Control The control uses the Membership service for creation of a new user. The control can be extended to the existing Wizard control. The control can be customized through templates and properties. Some of the properties, methods and events related to the control are as mentioned below: Properties of the Control Answer: It retrieves or specifies the answer to the password recovery confirmation question. CompleteStep: It shows the final step of the process for creating the user account. ContinueButtonText: It accesses or specifies the collection of properties defining the look of the control Email: It retrieves the email address of the user LoginCreatedUser: It accesses or specifies the value indicating the new user login once the account is created. Events of the control CreatedUser: It is initiated after the membership service provider has created a new user account CreatingUser: It is initiated before the membership service provider is called for creating user account SendingMail: It is initiated before sending the conformation email on the successful creation of the account SendMailError: It is initiated when the SMTP error occurs during the mail sent to the user. The CreateUserWizard control at the design time is as shown below: 7. ChangePassword Control The control helps user to change the password. The user adds the current password and adds the new password. If the old password is incorrect, the new one cannot be added. Properties of the control CancelDestinationPageUrl: It accesses or retrieves the URL of the page that the user is shown once it clicks the Cancel button. CurrentPassword: It retrieves the current password of a user. DisplayUserName: It retrieves the value indicating whether the ChangePassword control should be display the control and label NewPassword: It retrieves the new password entered by the user UserName: It shows the username for which the password is to be modified. Events of the control ChangedPassword: It is initiated when the password is changed for the user account. ChangePasswordError: It is initiated when there is an error in changing the password for the user account SendMailError: It is initiated when the SMTP error occurs during sending an email message The ChangePassword control at the design time is as shown below: Implementing Authentication in ASP.NET login controls Consider an example to demonstrate the login controls in an ASP.NET application. Perform the following steps to demonstrate the implementation of the login controls in application. Place the login control in the .aspx form and change the AutoFormat style property to Classic. Click the Smart Tag and open the Login Tasks and select the Administer Website option. Click the Security link in the window Click the Use the security Setup Wizard to configure security step by step link to open the setup wizard Click Next button in the welcome the security setup wizard. Click the From the Internet radio button and click the Next button. Click the Next button in the Advance provider settings page. Select the Enable roles for this web site check box and click the Next button Add the details in the text boxes and click the Create User button to create the user account. Select the All Users radio button in the Rule applies to section. Click the Add this Rule button. Click Next button Click Finish button, click Close button Add the LoginName and LoginStatus controls on the web page Set the LogoutAction property to Redirect, click the smart tag of the LoginStatus control and select the Logged In option from the Views drop down list. Execute the application and enter the username and password in the text boxes. Click Log In button. The following output is displayed when the application is executed on the server.