• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

Displaying user roles

There are many examples available that show how to provide custom output based on a user's role(s).  i.e.

If User.IsInRole("Administrator") then
  ' Display admin material
ElseIf User.IsInRole("Worker") then
  ' Display worker material
Else
  ' Display permission denied message
End If

It is possible to directly display a user's role without having to loop through all the possibilities using IF's and ELSE's?
Examples in vb please...!
0
Rouchie
Asked:
Rouchie
1 Solution
 
ihenryCommented:
>> It is possible to directly display a user's role..
No, unless you use reflection method. And it is not a good idea.

Workaround, snipet from ASP.NET Portal Starter Kit:

Public Shared Function IsInRoles(Byval roles As String) As Boolean
      HttpContext context = HttpContext.Current
      For Each role As string in roles.Split(';')
            If role <> "" And context.User.IsInRole(role) Then
                  return True;
            End If
      Next
      Return False
End Function

Usage, to check 2 roles at the same time:
Dim isAuthorized As Boolean = User.IsInRole( "Administrator;Worker" )
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now