Checking if User is in Role

Discussion in 'ASP .Net Security' started by mc, Apr 26, 2007.

  1. mc

    mc Guest

    I would like to check if a user is currently a member of a Local Group on the server. I am able to
    do the test for the current user and all is ok, however I would like to be able to take a list of
    users from a table in the database and check if the user is in the specified group. is it possible
    to take a username (as a string) and create an instance of IPricipal for that user? or achive by any
    other method?

    Regards


    MC
    mc, Apr 26, 2007
    #1
    1. Advertising

  2. "mc" <> wrote in message
    news:4630d7e6$...
    >I would like to check if a user is currently a member of a Local Group on
    >the server. I am able to do the test for the current user and all is ok,
    >however I would like to be able to take a list of users from a table in the
    >database and check if the user is in the specified group. is it possible to
    >take a username (as a string) and create an instance of IPricipal for that
    >user? or achive by any other method?
    >


    The following code returned true if UserName is a member of a Power Users
    group.
    DirectoryEntry entryRoot = new DirectoryEntry("WinNT://" +
    Environment.MachineName + ",computer",
    Environment.MachineName +"\\" + SuperUserName, SuperUserPassword,
    System.DirectoryServices.AuthenticationTypes.ReadonlyServer);
    DirectoryEntry userEntry = entryRoot.Children.Find(UserName, "user");
    DirectoryEntry objGroup = entryRoot.Children.Find("Power Users", "group");
    bool isMember = (bool)objGroup.Invoke("IsMember", new object[] {
    userEntry.Path.ToString() });

    SuperUserName is a local user
    Alexey Smirnov, Apr 26, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jesper Stocholm
    Replies:
    2
    Views:
    8,103
    John Saunders
    Aug 23, 2003
  2. Liet Kynes
    Replies:
    0
    Views:
    490
    Liet Kynes
    Nov 26, 2003
  3. Mark Chai
    Replies:
    1
    Views:
    739
    Christophe Vanfleteren
    Oct 1, 2003
  4. mc

    Checking if User is in Role

    mc, Apr 26, 2007, in forum: ASP .Net
    Replies:
    6
    Views:
    462
    Alexey Smirnov
    May 2, 2007
  5. Kursat
    Replies:
    1
    Views:
    312
    Dominick Baier
    May 7, 2007
Loading...

Share This Page