"Go" ASP. NET about the login control using

Source: Internet
Author: User

The original text reads as follows:

Today on the Internet to find some information about the login control, encountered a problem: the login control itself has a non-null authentication, that is, when the user does not enter a user name or password, the direct point submission will not pass validation, will appear after the user name and password "*", meaning the entry must be entered. I think if I don't want it to show "*", let's show "must fill in User name" and "must fill in Password" prompt message. Surfing the internet for half a day, just can't find the effect I want to achieve. At last, I did my own research. The display "*" is a feature of the login control itself, so I chose the right-click Control and chose "Convert to template" so that login is a combination of several controls. Show "*" is the RequiredFieldValidator validation control, change its Text property "*" to the prompt you want to display on the line.

Also, if you want to use ValidationSummary with the login control, simply set its ValidationGroup property to the ID of the login control.

Here are some of the properties and events that are reproduced from the web about the login control:

(Source: www.soAsp.net)

Login control

1. function
The login control is a composite control that provides all the common UI elements required to authenticate users on a Web site. The following three elements are required for all login scenarios:

Unique user name used to identify the user.

The password used to authenticate the user's identity.

The login button that is used to send login information to the server.

The Login control also provides the following optional UI elements that support additional functionality:

Password hint link.

The Remember Me check box that is used to retain logon information between two sessions.

A help link for users who are having trouble signing in.

Redirect the user to the register new user link on the registration page.

The description text that appears on the login form.

The custom error text that appears when the user clicks the login button without filling in the user name or password field.

The custom error text that appears when the login fails.

The custom action that occurs when the login succeeds.

How to hide login controls when a user is logged on to a site

2. Properties
The Login control section commonly used properties and descriptions, as shown in table 1.

Table 1 most common properties and descriptions of the login control

Property Description

Createusericonurl gets the location of the image that appears next to the link to the new User's registration page

Createusertext Gets or sets the link text for the New user registration page

Createuserurl Gets or sets the URL of the new user registration page

Destinationpageurl Gets or sets the URL of the page that is displayed to the user when the logon attempt succeeds

Failureaction Gets or sets the action that occurs when a logon attempt fails

FailureText Gets or sets the text that is displayed when the logon attempt fails

Helppagetext Gets or sets the text of the login Help page link

Helppageurl Gets or sets the URL of the sign-in Help page

Loginbuttontext Gets or sets the text of the login button for the login control

Loginbuttontype Gets or sets the type of button used when the login button is rendered

MembershipProvider Gets or sets the name of the membership data provider that the control uses

Orientatio Gets or sets a value that specifies the location of the elements of the login control on the page

Passwordlabeltext Gets or sets the label text of the Password text box

Passwordrecoverytext Gets or sets the text of the Password recovery page link

Passwordrecoveryurl Gets or sets the URL of the password recovery page

Passwordrequirederrormessage Gets or sets the error message that is displayed in the ValidationSummary control when the password field is empty

Remembermetext Gets or sets the label text of the Remember Me check box

TEXTLAYOUT Specifies the location of each label of the Login control relative to its associated text box

TitleText Gets or sets the caption of the login control

UserName Gets the user name entered by the user

Usernamelabeltext Gets or sets the label text of the username text box

Usernamerequirederrormessage Gets or sets the error message that is displayed in the ValidationSummary control when the user name field is empty

ValidatorTextStyle gets a reference to a collection of Style properties that define the appearance of the error information associated with the validator used by the login control

VisibleWhenLoggedIn Gets or sets a value that indicates whether the Login control is displayed after authenticating the user

The more important attributes are described in more detail below.

(1) Createusertext property

This property gets or sets the link text for the new user registration page.

Grammar:

Public virtual string Createusertext {get; set;}


Property value:

The link text for the new user registration page. The default is empty.

Description: The Createusertext property contains the link text for the site registration page. Specify the URL of the registration page in the Createuserurl property. If Createuserurl is empty, the text in the Createusertext property is displayed to the user but is not displayed as a link. If the Createusertext property is empty, no registration page link is provided to the user

(2) Createuserurl property

This property is used to set the URL of the new user registration page, which contains the URL of the new user registration page for the site.

Grammar:

Public virtual string Createuserurl {get; set;}


Property value:

The URL of the new user registration page. The default is empty.

Description: The Createusertext property contains the text used by the link. If the Createusertext property is empty, the user is not provided with a link to the registration page.

(3) Destinationpageurl property

This property gets or sets the URL of the page that is displayed to the user when the logon attempt succeeds.

Grammar:

Public virtual string Destinationpageurl {get; set;}


Property value:

The URL of the page to which the user was redirected when the logon attempt was successful. The default is empty.

For example: Login successfully to the "default2.aspx" page. The code is as follows:

Login1.destinationpageurl = "~/default2.aspx";


(4) Failureaction property

This property gets or sets the action that occurs when a logon attempt fails.

Grammar:

Public virtual loginfailureaction failureaction {get; set;}


Property value:

One of the Loginfailureaction enumeration values. The default is refresh.

The Loginfailureaction enumeration values and descriptions are shown in table 5.

Table 5 Loginfailureaction enumeration values and descriptions

Enumeration value Description

Redirecttologinpage redirect users to the login page defined in the site's configuration file (machine.config and Web. config)

Refresh refreshes the current page so that the login control can display an error message

(5) Helppageurl Property

This property gets or sets the URL of the sign-in Help page.

Grammar:

Public virtual string Helppageurl {get; set;}


Property value:

The URL of the sign-in Help page. The default is empty.

Description: The Helppageurl property contains the URL of the site's sign-in help page. The Helppagetext property contains the text for the link. If Helppageurl is empty, the text in the Helppagetext property is displayed to the user but is not displayed as a link. If the Helppagetext property is empty, the user is not provided with a link to the login help page.

(6) Helppagetext property

This property gets or sets the text of the sign-in Help page link

Grammar:

Public virtual string Helppagetext {get; set;}


Property value:

The text that is linked to the sign-in Help page. The default is empty.

(7) Loginbuttontype Property

This property gets or sets the type of button that is used when the login button is rendered.

Grammar:

Public virtual ButtonType Loginbuttontype {get; set;}


Property value:

One of the ButtonType enumeration values. The default is button. The ButtonType enumeration values and descriptions are shown in table 6.

Table 6 ButtonType enumeration values and descriptions

Enumeration value Description

button command buttons

Image Display button

Link hyperlink-style buttons

(8) Passwordrecoveryurl Property

This property gets or sets the URL of the password recovery page.

Grammar:

Public virtual string Passwordrecoverytext {get; set;}


Property value:

The text of the Password recovery page link. The default is empty.

(9) Passwordrequirederrormessage Property

This property gets or sets the error message that is displayed in the ValidationSummary control when the user name field is empty

Grammar:

Public virtual string Passwordrequirederrormessage {get; set;}


Property value:

The error message that is displayed in the ValidationSummary control when the password field is empty. The default value is "password".

(Remembermetext) Property

This property gets or sets the label text for the Remember Me check box.

Grammar:

Public virtual string Remembermetext {get; set;}


Property value:

Label text for the "Remember Me" check box. The default is next "Remember Me".

(one) Usernamerequirederrormessag properties

Gets or sets the error message that is displayed in the ValidationSummary control when the user name field is empty.

Grammar:

Public virtual string Usernamerequirederrormessage {get; set;}


Property value:

The error message that is displayed in the ValidationSummary control when the user name field is empty. The default is "user name".

(VisibleWhenLoggedIn) Properties

This property gets or sets a value that indicates whether the login control is displayed after authenticating the user.

Grammar:

Public virtual bool VisibleWhenLoggedIn {get; set;}


Property value:

False if the login control is hidden after authenticating the user, otherwise true. The default is true.

This example uses the login control to implement the membership user login site to verify the user name and password. Example run, enter the user name "Mr", password "mr.soft" to login to the website.
The Login control design code is as follows.

<asp:login id= "Login1" runat= "Server" backcolor= "#F7F7DE" bordercolor= "#CCCC99" borderstyle= "Solid"
Borderwidth= "1px" destinationpageurl= "~/default.aspx" font-names= "Verdana" font-size= "10pt" >
<titletextstyle backcolor= "#6B696B" font-bold= "True" forecolor= "#FFFFFF"/>
</asp:Login>


3. Events
Common events and descriptions for the login control, as shown in table 7.

Table 7 common events and descriptions for the login control

Event description

Authenticate appears after verifying the user's identity

LoggedIn occurs after a user logs on to a Web site and authenticates

Loggingin occurs when a user submits logon information without authentication

LoginError occurs when a login error is detected

The following is a detailed description of the more important events.

(1) Authenticate event

Appears after verifying the user's identity. The authenticate event is raised when a user logs on to a Web site by using the login control. A custom authentication scheme can use the authenticate event to authenticate a user. Defining the authentication scheme the authenticated property should be set to true to indicate the identity of the authenticated user.

Grammar:

Public event Authenticateeventhandlerauthenticate


Description: After the user submits the login information, the login control raises the Loggingin event first, then raises the authenticate event, and finally raises the Loggedin event.

This example uses the login control's authenticate event to implement a custom user login site. Example run, enter the user name "System", the password "111" to log on to the Web site.

The code is as follows.
protected void Login1_authenticate1 (object sender, AuthenticateEventArgs e)
{
System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection ("server=zhy//zhy;uid=sa;pwd=; Database=aspnetdb ");
Con. Open ();
String strSQL = "SELECT * from tb_01 where userid= '" + Login1.UserName.ToString () + "' and username= '" + Login1.password + "‘";
System.Data.SqlClient.SqlCommand com = new System.Data.SqlClient.SqlCommand (strSQL, con);
System.Data.SqlClient.SqlDataReader dr = com. ExecuteReader ();
if (Dr. Read ())
{
e.authenticated = true;//Passed validation
}
Else
{
e.authenticated = false;
}
Dr. Close ();
Con. Close ();
}


4. Typical examples
This example implements a comprehensive application of the login control, using the login control to enable the membership user to log on to the Web site. Run the instance "Login.aspx" page, enter the username "Soasp_net", and the password "111" to log on to the Web site.

The main code is as follows. <asp:login id= "Login1" runat= "Server" backcolor= "#F7F7DE" bordercolor= "#CCCC99" borderstyle= "Solid" borderwidth= " 1px "font-names=" Verdana "font-size=" 10pt "destinationpageurl=" ~/index.aspx "> <titletextstyle backcolor=" # 6b696b "font-bold=" True "forecolor=" white "/>
</asp:Login>

Original address:

http://blog.csdn.net/devillyd/article/details/6197294

"Go" ASP. NET about the login control using

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.