Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 3870 Prog6 Roles Management Due Monday, November 5 Group Assignment.

Similar presentations


Presentation on theme: "CS 3870 Prog6 Roles Management Due Monday, November 5 Group Assignment."— Presentation transcript:

1 CS 3870 Prog6 Roles Management Due Monday, November 5 Group Assignment

2 Roles Better approach to manage multiple users
Roles for Prog6: Admin and Member Users in role Admin can access pages of Admin, but not pages of Member Users in role Member cannot access pages of Admin, but can access pages of Member One user could be in multiple roles

3 New User UserName: Windows Password: cs3340@UWP Email: your UWP email
Other: your choice

4 New User UserName: WebApps Password: cs3870@UWP Email: your UWP email
Other: your choice

5 New User UserName: Qi Password: 213@Ullrich Email: your UWP email
Other: your choice

6 Users and Roles WebApps Windows Qi csse Admin and Member Member Admin
Not in any roles

7 Web.config under the root folder
Enabling RoleManager Web.config under the root folder <system.web> <roleManager defaultProvider="AlphaRoleProvider" enabled="true" cacheRolesInCookie="true" cookieName=".ASPROLES" cookieTimeout="30" cookiePath="/" cookieRequireSSL="false" cookieSlidingExpiration="true" cookieProtection="All"> <providers> <clear/> <add name="AlphaRoleProvider“ type="UWPCS3870.AlphaRoleProvider" connectionStringName="AlphaConnectionString" applicationName="CS3870" writeExceptionsToEventLog="false"/> </providers> </roleManager> </system.web>

8 Page SetRoles

9 Page Load //Load event initializes dropdown boxes. protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) return; try ListUsersBind(); //get all users ListRolesBind(); //get all roles ListUsersInRolesBind(); } catch(Exception ex) . . .

10 //Binds all users to dropdown.
private void ListUsersBind() { lstUsers.DataSource = Membership.GetAllUsers(); lstUsers.DataBind(); }

11 //Binds roles to dropdown.
private void ListRolesBind() { try lstRoles.DataSource = Roles.GetAllRoles(); lstRoles.DataBind(); } catch(Exception ex) txtMessage.Text = ex.Message;

12 //Binds users of a certain role to dropdown.
private void ListUsersInRolesBind() { try lstUsersInRoles.DataSource = Roles.GetUsersInRole(lstRoles.SelectedValue); lstUsersInRoles.DataBind(); } catch(Exception ex) txtMessage.Text = ex.Message;

13 //Adds a role to the system.
protected void btnAddRole_Click(object sender, EventArgs e) { try //Role name is txtRoles.Text Roles.CreateRole(txtRoles.Text); txtMessage.Text = "Role " + txtRoles.Text + " has been added"; ListRolesBind(); ListUsersInRolesBind(); } catch(Exception ex) txtMessage.Text = ex.Message; protected void btnRemoveRole_Click( )

14 //Adds a user to a role. protected void btnAddUserToRole_Click(. . .) { try Roles.AddUserToRole(lstUsers.Text, lstRoles.SelectedValue); txtMessage.Text = "User " + lstUsers.Text + " has been added to the role " + lstRoles.Text; ListUsersInRolesBind(); } catch(Exception ex) txtMessage.Text = ex.Message; protected void btnRemoveUserFromRole_Click( )

15 ‘ AutoPostBack: True Protected Sub lstRoles_SelectedIndexChanged(. . .) Handles lstRoles.SelectedIndexChanged ListUsersInRoleBind() End Sub

16 //Deletes a user. protected void btnDeleteUser_Click(object sender, EventArgs e) { try Membership.DeleteUser(lstUsers.Text, true); txtMessage.Text = "User " + lstUsers.Text + " has been deleted."; ListUsersBind(); ListUsersInRolesBind(); } catch(Exception ex) txtMessage.Text = ex.Message;

17 Main Web.Config <location path="Prog6/Member">
<system.web> <authorization> <allow roles=“Member"/> <deny users=“*" /> </authorization> </system.web> </location> <location path="Prog6/Admin"> <allow roles="Admin"/> <deny users="*" />

18 Authorization Configuration File under the folder Admin
<system.web> <authorization> <allow roles="Admin"/> <deny users="*" /> </authorization> </system.web>

19 Authorization Configuration File under the folder Member
<system.web> <authorization> <allow roles=“Member"/> <deny users="*" /> </authorization> </system.web>

20 Need One of Them, Not Both
Main Web.config Web.config in subfolder

21 WebSite and ApplicationName
Each student has a website on Alpha Physical folder Name: UWP username Website name in IIS : UWP username IIS Applicationpool : UWP username ApplicationName for membership and role management In the main Web.config

22 Prog 6 Must change the ApplicationName for both membership and role management to your UWP username Same on Test 2

23 Login UserName Displayed on program Master Page
Could save it using Session variable Session("Prog6_UserName") = Page.User.Identity.Name Retrieve the UserName on any pages

24 You should be able to do it yourselves!
Total on Page Checkout You should be able to do it yourselves!

25 Site Map XML File Web.sitemap
Organize the pages in the site hierarchically Must be located in the application root directory Automatically picked up by the default site-map provider SiteMapDataSource

26 Creating File Web.sitemap
Right click the application root Add Add New Site Map It could be created in a sub-folder, but won’t be recognized

27 Initial Web.sitemap <?xml version="1.0" encoding="utf-8" ?> <siteMap xmlns=" > <siteMapNode url="" title="" description=""> <siteMapNode url="" title="" description="" /> </siteMapNode> </siteMap>

28 Web.sitemap Contains only one siteMapNode element
The root node can contain any number of child siteMapNode elements The child notes can have their child notes Note Properties URL: can be empty, but no duplicate Title Description

29 Test 2 November 8 Group Test Prog5 and Prog6
Authentication and Authorization Login Create User and Roles Assign users to roles Accessing Database


Download ppt "CS 3870 Prog6 Roles Management Due Monday, November 5 Group Assignment."

Similar presentations


Ads by Google