locked
AD Group RRS feed

  • Question

  • User265788195 posted
    How can I verify whether a logged on user belongs to the Active Directory User Group.
    Thursday, April 5, 2007 6:46 PM

All replies

  • User-319574463 posted
    Have a look at http://www.15seconds.com/issue/020730.htm http://www.wwwcoder.com/main/parentid/260/site/2208/68/default.aspx and http://15seconds.com/issue/060525.htm
    Sunday, April 8, 2007 6:10 PM
  • User265788195 posted

    The below code is what I have for now.I want to use this code  to even go through the sub group and find that the user is the member of the main group.  

    public static bool IsValidUser(string domainId, string mygroupname)

    {

    string _memberGroup = "";

    bool _flag = false;

    DirectorySearcher ds = new DirectorySearcher(de);

    ds.Filter = "(SAMAccountName=" + domainId + ")";

    ds.PropertiesToLoad.Add("memberOf");

    string groupName = "";

    try

    {

    SearchResult result = ds.FindOne();

    int propertyCount = result.Properties["memberOf"].Count;

    String dn;

    int equalsIndex, commaIndex;

    for (int propertyCounter = 0; propertyCounter < propertyCount; propertyCounter++)

    {

    dn = (String)result.Properties["memberOf"][propertyCounter];

    equalsIndex = dn.IndexOf("=", 1);

    commaIndex = dn.IndexOf(",", 1);

    if (-1 == equalsIndex)

    {

    return false;

    }

    groupName = dn.Substring((equalsIndex + 1), (commaIndex - equalsIndex) - 1);

    if (groupName.ToUpper() == mygroupname.ToUpper())

    {

    _flag = true;

    }

    }

    }

    catch (Exception ex)

    {

    throw new Exception("Error obtaining the group name. " +

    ex.Message);

    }

    return _flag;

    }

    Wednesday, April 11, 2007 6:11 PM