Use ASP. NET to configure roles

Source: Internet
Author: User
Tags strong password

Set role management and logon controls using ASP. NET
1. Preparations
1. Create a new master page and the following folders and pages (these pages inherit the template pages)
Default. aspx
Login. aspx
Masterpage. Master
Recovery. aspx
Register. aspx
Admin (folder) admin_default.aspx (in the admin folder)
Member (folder) member_default.aspx (in the member folder)
VIP (folder) vip_default.aspx (in the VIP folder)
2. create a site map and design the master page (see the bottom figure) (where "User Name" and "login" are dragged into the Toolbox (the loginname and loginstatus of login ), the left-side Treeview is a navigation control, and the Treeview is bound to the site map)

Site map code
<? XML version = "1.0" encoding = "UTF-8"?>
<Sitemap xmlns = "http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
<Sitemapnode url = "~ /Default. aspx "Title =" default "Description =" ">

<Sitemapnode url = "" Title = "admin" Description = "" roles = "admin">
<Sitemapnode url = "~ /Admin/admin_default.aspx "Title =" admin_default "Description =" "roles =" admin "/>
</Sitemapnode>
<Sitemapnode url = "" Title = "VIP" Description = "" roles = "Admin, VIP">
<Sitemapnode url = "~ /VIP/vip_default.aspx "Title =" vip_default "Description =" "roles =" Admin, VIP "/>
</Sitemapnode>
<Sitemapnode url = "" Title = "member" Description = "" roles = "Admin, VIP, member">
<Sitemapnode url = "~ /Member/member_default.aspx "Title =" member_default "Description =" "roles =" Admin, VIP, member "/>
</Sitemapnode>

<Sitemapnode url = "~ /Login. aspx "Title =" login "Description =" "/>
</Sitemapnode>
</Sitemap>

3. Create a virtual directory in IIS, set the minimum password length to 2, and set the strong type to 0.

IIS virtual directory
1. IIS virtual directory
Run (MMC)-> file (Add/delete Management Unit)-> Add (Select Internet Information Service, add or close)-> open a node (right-click the default website attribute, create a virtual directory, alias (such as temp), Click Browse, find the site to be deployed, such as c: \ Documents ents and Settings \ Administrator \ Desktop \ tempdemo \ webui, in fact, the folder used to save the page is selected. The webui folder contains the page (default_repeater.aspx ))
2. Change the minimum password length to 2 and the strong password type to 0 (mainly for visual configuration)
Under the default website, right-click temp (the alias you just created) --> select Properties, select ASP. NET (select 2.0 for the version number, then click Edit configuration, select authentication)
--> Click the management provider-> change minrequiredpasswordlength to 2, and change minrequirednonalphanumericcharachers to 0,
When you enter the Visual Studio interface, a dialog box is displayed, asking whether the Web. config file has been modified and whether to reload the file. Select "all"

2. Click ASP. NET configuration in the solution on the Visual Studio interface.

ASP. NET Configuration
Enter ASP. net configuration --> select Security (click "use Security Settings wizard") --> enable roles for this website through the Internet --> create three roles (Admin, VIP, member) --> register three consecutive users (Admin, VIP, member) --> access to Singapore
1. Anonymous user, allow, click to add this rule
2. Open webui and select the following admin --> first (role admin, allow, click to add this rule) --> (all users, deny, add this rule)
3. Open webui and select the following VIP-> first (here, allow the role admin and then allow the VIP)-> (all users, deny, add this rule)
4. After clicking finish, the page will be retrieved (secure). In the user (Click Manage user)-> edit role (Select Admin role as admin and click Next after clicking finish)
5. If the Treeview node is incorrectly displayed after logging on to the role's account, check ASP. NET configuration --> select whether the role in security is enabled
Rule: the higher the permission, the higher the permission. How to understand: from the bottom up, allow all, allow anonymous, deny all, and then allow the Administrator (the last two steps are the key)

3. The following describes how to use the "Login control" on the page.

1. login page
1. (drag the login control to this page when logging on to the Toolbox) --> convert to a template (drag two linkbuttons to "remember me" next time to register and forget the password)
2. Background Code: (2 linkbutton redirection)
Protected void lbtn_register_click (Object sender, eventargs E)
{
Response. Redirect ("~ /Register. aspx ");
}
Protected void lbtn_recovery_click (Object sender, eventargs E)
{
Response. Redirect ("~ /Recovery. aspx ");
}
2. register page
1. drag createuserwizard to the page in the toolbox login (click the Custom User Creation step) --> insert a row under the security answer (Operation: right-click the Security answer, right-click it, and insert the following rows. --> drag a radiobuttonlist (click to select items) in the toolbox. --> Add three members (Admin, VIP, Member, text, and value are both set the same (for example, admin), and then set the selected value of member to true (indicating that it is a member by default )) --> set the repeaterdirection attribute of radiobuttonlist to horizontal.
2. Create a user (set the role of this user)
Radiobuttonlist RBL = createuserwizard1.createuserstep. contenttemplatecontainer. findcontrol ("radiobuttonlist1") as radiobuttonlist;
Roles. addusertorole (createuserwizard1.username, RBL. selectedvalue );
3. Click the upper right triangle --> Custom User (to enable the registered user to register, you can directly go to the home page)
Response. Redirect ("~ /Default. aspx ");
4. Go back to the upper right corner of the page and change "complete" to "register a new user" in the step-down list"

4. Finally, you want the Treeview to display different contents for different roles.
1. Visibility is configured in the site map. In different nodes, add a roles = "Admin, VIP", for example, the following node and an additional roles attribute.
<Sitemapnode url = "~ /Admin/admin_default.aspx "Title =" admin_default "Description =" "roles =" admin "/>
2. permissions have been set in ASP. NET configuration> Security (the second step above is set in ASP. NET configuration)
3. Add the following code before </system. Web> in Web. config.
<Sitemap defaultprovider = "aspxmlsitemapprovider" enabled = "true">
<Providers>
<Add name = "aspxmlsitemapprovider" type = "system. web. xmlsitemapprovider, system. web, version = 2.0.3600.0, culture = neutral, publickeytoken = b03f5f7f11d50a3a "sitemapfile =" Web. sitemap "securitytrimmingenabled =" true "/>
</Providers>
</Sitemap>

5. Download Code: Download

Related Article

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.