locked
How to check roles/groups of other users (not current user) ? RRS feed

  • Question

  • User751502845 posted

    Hi, I have an asp.net application which is able to authenticate against Windows active directory.  That part works fine.  When a certain user logs in, I want him to be able to check if another user is in a certain role/group.

    I tried using Role.IsUserInRole(String username, String rolename) but the application throws an error saying that the current user can only check if the current user is in a role/group.  If that is so, then would be the point of the first parameter of this method if the only user that can be checked is only the current user?  So it looks like the first parameter will always need to be "User.Identity.Name".

    Is there an easy way for the current user to check if another user is a member of a role/group?  If it isn't a simple task, can you point me in the right direction, since I haven't really done this before.  Thanks in advance.

    Wednesday, January 9, 2013 2:16 PM

Answers

  • User-166373564 posted

    Hi S2kDriver

    I think Roles.IsUserInRole Method (String, String) method and WebSecurity.UserExists( ) method are available for you,

    if ((WebSecurity.UserExists( ) ) && (Roles.IsUserInRole(String username, String rolename)))

    You could also refer the usage of Roles.IsUserInRole Method (String, String) method and WebSecurity.UserExists( ) method below,

    Roles.IsUserInRole Method (String, String)

    WebSecurity.UserExists Method

    hope it helps you,

    Kind regards

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 15, 2013 4:09 AM