The first is a series of security-related classes, and now we can use these classes to make our own security system. In fact, the purpose of Microsoft is far from this, let's look at Microsoft to provide us with the Login series control.
The Login series controls are Microsoft's approach to simplifying our development process and providing us with a common security development.
The Login series control contains the following controls:
Login logon Control
LoginName controls to display the user name
LoginStatus displays different information depending on the user's login status (login, logout)
LoginView display different templates depending on the login status
CreateUserWizard provides a wizard template for registering user accounts
ChangePassword Change Password
PasswordRecovery used to retrieve the password when the password is forgotten
The lower layers of the above controls are integrated with MEMBERSHIPAPI, which are independent of each other and can be used alone or in a more complete security management.
Login control:
The login interface contains the user name, password, and login buttons.
Property:
Destinationpageurl a page that is high after the user logs on successfully
Failureaction Login failed operation, refresh and redirecttologinpage two operations
Remembermeset set the "Remember Me" check control.
Createuserurl Registered User Account page
Helppageurl URL of the description page
Passwordrecoveryurl URL of Password recovery page
The login control provides a series of predefined styles that can be selected from the smart menu by tapping AutoFormat .... You can also select Convert to template to set the style you want to display.
When you enter a user name and password to log in, the login control will automatically go to the database to verify the user name and password entered.
Custom Authentication Event Handling:
The login control's underlying is validated using the Membership.validate () and Formsauthentication.redirectfromlogin () methods, but sometimes we have existing user accounts and databases. So how do I log in?
protected void Login1_authenticate (object sender, AuthenticateEventArgs e)
{
String str = webconfigurationmanager.connectionstrings["LocalSqlServer"]. ConnectionString;
SqlConnection conn = new SqlConnection (str);
Conn. Open ();
SqlCommand cmd = conn. CreateCommand ();
Cmd.commandtext = "SELECT count (*) from login where username = @u and password = @p";
SqlParameter param;
param = new SqlParameter ("@u", login1.username);
Cmd. Parameters.Add (param);
param = new SqlParameter ("@p", Login1.password);
Cmd. Parameters.Add (param);
int n = (int) cmd. ExecuteScalar ();
Conn. Close ();
if (n > 0)
E.authenticated = true;
Else
e.authenticated = false;
}
Customizing the Login control template
The existing login control may seem too monotonous if you want to customize how the login control should work? Click the smart tag "convert to template" so that you can set up your own controls.
The ID property of the textbox for the account must be set to: UserName
The ID property of the textbox for the password must be set to: Password
The CommandName property of the login button must be set to login
LoginName Control:
You can do this by dragging the LoginName control to the interface.
LoginStatus Control:
The LoginStatus control is a hyperlink that displays "login" when not logged in, and "Log off" after login to prompt the user to log in or log out. The operating principle behind it is request.isauthentication or User.Identity.IsAuthenticated as the basis of judgment. If the login fails, go to the page specified in the Web. config file and if successful, go to the page where the LoginStatus control is located.
Property:
LoginText: Set or get login text
Logouttext: Set or get logout text
Loginimageurl: Sets the picture of the login hyperlink.
Logoutimageurl: Sets the picture of the logout hyperlink.
LogoutAction: Post-logoff operation, Refresh, Redirect, Redirecttologinpage
Logoutpageurl: If the LogoutAction property is set to redirect, log off and go to the URL set by Logoutpageurl
LoginView Control:
By default, there are two templates: AnonymousTemplate and LoggedInTemplate, which are anonymous users and two templates after login, so you can display different interfaces for both anonymous and logged-in users.
In addition, the LoginView control can create different templates based on different roles. Select Edit RoleGroups for the smart tag to add a new template, and then select the role template you want to edit in the view to define the style of the role template.
Note: If a user has more than one role, then when he logs in, the LoginView control displays the template for his first role, not the template for all his characters.
CreateUserWizard CONTROLS:
The CreateUserWizard control provides a user-registered interface, which is a wizard control that can apply its own style, which is simple and simple, and complex enough to say. Just so it's simple, because when you just create a simple registration page, drag it to the page and set the style to work. It's complicated because it's so flexible that you can customize the template and add some of your own user personalization information. I don't want to say much here, it's a wizard control, so it's custom functionality that I'll explain in detail later in the wizard control.
ChangePassword Control:
The ChangePassword control is a control in which a user changes a password, but only the user who is authenticated is allowed to change, and the original old password is required.
PasswordRecovery Control:
When the user forgets the password can pass the system security question, if the answer is correct the system will automatically send an email to this account user, contains the password.
This feature is a prerequisite for your site to be set up with the SMTP service
Set in Web. config:
<system.net>
<mailSettings>
<SMTP from= "[email protected]" >
<network host= "192.168.1.2" password= "username=" "/>
</smtp>
</mailSettings>
</system.net>
Or:
Web site-ASP, open ASP. NET Web Application Manager, and then select Applications-Configure SMTP e-mail settings to set up your mail content on a new page.
(Che Yanlu)
Collected in 2007-07-11
asp.net2.0 Security (4)--login series Control--reprint from the car teacher