Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing roles in ASP.NET
    text
    copied!<p>In asp.net web application I have restricted users actions depending on their roles like as follow</p> <p>I have created three tables in database</p> <p>Tables </p> <p>Table: Users</p> <pre><code>UserID Username Password 1 Bob password1 2 Scott password2 3 Jisun password3 4 Sam password4 5 John password5 </code></pre> <p>Table:Groups</p> <pre><code>GroupID Name 1 Administrators 2 Clerk 3 Manager 4 Cashier </code></pre> <p>Table:Roles</p> <pre><code>UserID GroupID 1 1 2 2 2 3 3 4 4 3 4 4 </code></pre> <p>In Global.asax file I have written the following </p> <pre><code>Sub Application_AuthenticateRequest(sender As Object, e As EventArgs) If Request.IsAuthenticated Then 'Determine this user's roles Dim reader As SqlDataReader = _ SqlHelper.ExecuteReader(connection string, _ CommandType.StoredProcedure, "rolesForUser", _ New SqlParameter("@Username", User.Identity.Name)) ' Create an array of role names Dim roleList As New ArrayList Do While reader.Read() roleList.Add(reader("Name")) Loop 'Convert the roleList ArrayList to a String array Dim roleListArray As String() = roleList.ToArray(GetType(String)) 'Add the roles to the User Principal HttpContext.Current.User = _ New GenericPrincipal(User.Identity, roleListArray) End If End Sub </code></pre> <p>And in asp.net code-behind file the following code</p> <pre><code>If User.IsInRole("Administrator") then ' Display sensitive material ElseIf User.IsInRole("Clerk") then ' Display moderately sensitive material Else ' Display only bland material End If </code></pre> <p>as of now it is working fine. Now a new requirement has araised that to allow the clerk to access some of (but not all) functionalities perfomred by administrator.</p> <p>Do i need to change my source code to provide above new requirement?</p> <p>Do I need to do the same again and again when such requirement araises in future ?</p> <p>or anyother better way I can do please suggest me.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload