Exploring Login Controls in ASP.NET

Discussion in 'ASP.NET' started by MinalS, Feb 22, 2015.

  1. MinalS

    MinalS New Member

    Joined:
    Jul 8, 2014
    Messages:
    138
    Likes Received:
    32
    Trophy Points:
    0
    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.
    1. Login Control
    2. The LoginView Control
    3. The LoginStatus Control
    4. LoginName Control
    5. PasswordRecovery Control
    6. CreateUserWizard Control
    7. 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:
    1. CreateChildControls: It creates an individual control of the Login control and the event handlers are associated with it.
    2. OnLoggingIn: It raises the LoggingIn event when the user adds the login data before the authentication is completed.
    3. OnLoggedIn: It raises an LoggedIn event when the user log into the web site after the authentication is completed
    4. OnAuthenticate: It raises an Authenticate event for the user authentication.
    Properties of the Login Control
    1. CreateUserIconUrl: It retrieves the location of the image to display the link to the user.
    2. CreateUserUrl: It specifies or retrieves the URL for the new user page.
    3. DisplayRememberMe: It specifies the value stating whether to display the RememberMe checkbox.
    4. FailureText: It displays the text when the login attempt fails
    5. HelpPageText: It specifies the text of link to the login help page.
    6. Password: It retrieves the password entered by the user
    Events of the Login Control
    1. LoggedIn: It is initiated when the user logs in the web site and is authenticated.
    2. LoggingIn: It is initiated when the user submits the login information.
    3. LoginError: It is initiated when a login error is detected.
    The Login control at the design time is as shown below:

    [​IMG]

    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
    1. DataBind: It helps user to bind the data source through the LoginView control.
    2. OnViewChanged: It raises the ViewChanged event after the view for the control is changed.
    3. OnViewChanging: It raises the ViewChanging event before the LoginView control changes the view.
    Properties of the LoginView class
    1. Controls: It accesses the ControlCollection object containing the child controls for the LoginView control
    2. EnableTheming: It access or specifies the value indicating the themes to be applied to the control
    3. RoleGroups: It access the collection of role groups associated with the content templates
    Events of the LoginView class
    1. ViewChanged: It is initiated when the view is changed
    2. 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:

    [​IMG]

    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
    1. OnLoggedOut: It raises the event when the logout link is clicked by the user.
    2. OnLoggingOut: It raises the event when the user clicks the logout link of the control.
    Properties of the LoginStatus Control
    1. LoginImageUrl: It accesses or specifies the URL of the image used for the login link.
    2. LoginText: It access the text added for the login link
    3. LogoutAction: It retrieves the value for determining the action when the user logs out of the web site.
    4. LogoutText: It retrieves the text used for logout the link
    Events of the LoginStatus Control
    1. LogginOut: It is initiated when the user sends the logout request to the server.
    2. 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:

    [​IMG]

    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:

    [​IMG]


    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.
    1. Question: It refers the view where the user can enter the answer to the security question.
    2. UserName: It refers to the view where the user can enter the username for the password to be recovered.
    3. 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
    1. OnSendingMail: It raises the SendingMail event when the user is verified and the password is sent to the user.
    2. OnUserLookupErrror: It raises the UserLookupError when the username does not match with the one stored in the database,
    3. OnSendMailError: It raises an error when the mail message is not sent to the user.
    4. OnVerifyingUser: It raises the event once the username is submitted, and the membership provider verification is pending.
    Properties of the control
    1. Answer: The answer provided by the user to confirm the password recovery through the valid user
    2. FailureTextStyle: It accesses the reference to the collection of properties defining the error text look
    3. HelpPageIconUrl: It image to be displayed for the link to the password is retrieved
    Events of the control
    1. SendingMail: It is initiated when the server is sending an email message containing the password once the answer is correct
    2. AnswerLookupError: It is initiated when the user answer to the question is incorrect
    3. 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:

    [​IMG]

    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
    1. Answer: It retrieves or specifies the answer to the password recovery confirmation question.
    2. CompleteStep: It shows the final step of the process for creating the user account.
    3. ContinueButtonText: It accesses or specifies the collection of properties defining the look of the control
    4. Email: It retrieves the email address of the user
    5. LoginCreatedUser: It accesses or specifies the value indicating the new user login once the account is created.
    Events of the control
    1. CreatedUser: It is initiated after the membership service provider has created a new user account
    2. CreatingUser: It is initiated before the membership service provider is called for creating user account
    3. SendingMail: It is initiated before sending the conformation email on the successful creation of the account
    4. 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:

    [​IMG]

    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
    1. CancelDestinationPageUrl: It accesses or retrieves the URL of the page that the user is shown once it clicks the Cancel button.
    2. CurrentPassword: It retrieves the current password of a user.
    3. DisplayUserName: It retrieves the value indicating whether the ChangePassword control should be display the control and label
    4. NewPassword: It retrieves the new password entered by the user
    5. UserName: It shows the username for which the password is to be modified.
    Events of the control
    1. ChangedPassword: It is initiated when the password is changed for the user account.
    2. ChangePasswordError: It is initiated when there is an error in changing the password for the user account
    3. 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:

    [​IMG]

    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.
    1. Place the login control in the .aspx form and change the AutoFormat style property to Classic.

      [​IMG]
    2. Click the Smart Tag and open the Login Tasks and select the Administer Website option.
    3. Click the Security link in the window

      [​IMG]
    4. Click the Use the security Setup Wizard to configure security step by step link to open the setup wizard
    5. Click Next button in the welcome the security setup wizard.

      [​IMG]
    6. Click the From the Internet radio button and click the Next button.

      [​IMG]
    7. Click the Next button in the Advance provider settings page.

      [​IMG]
    8. Select the Enable roles for this web site check box and click the Next button

      [​IMG]
    9. Add the details in the text boxes and click the Create User button to create the user account.

      [​IMG]
    10. Select the All Users radio button in the Rule applies to section.
    11. Click the Add this Rule button. Click Next button

      [​IMG]
    12. Click Finish button, click Close button
    13. Add the LoginName and LoginStatus controls on the web page
    14. 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.
    15. Execute the application and enter the username and password in the text boxes. Click Log In button.
    16. The following output is displayed when the application is executed on the server.
      [​IMG]
     
    Last edited by a moderator: Jan 21, 2017

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice