Displaying user roles

Posted on 2005-04-06
Last Modified: 2013-03-01
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
  ' 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...!
Question by:Rouchie
    1 Comment
    LVL 20

    Accepted Solution

    >> 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
          Return False
    End Function

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now