mathieu_cupryk
asked on
add a username to check in the follow function.
I would like to modifiy the function below and check for the username in the group of members.
string fullname = System.Security.Principal. WindowsIde ntity.GetC urrent().N ame.ToStri ng();
string[] parts = fullname.Split('\\');
string sDomain = parts[0];
string sUser = parts[1];
string sGroup = "gl ca corporate data";
StringCollection groupMembers = this.GetGroupMembers(sDoma in, sGroup, sUser);
I have a function that gets group members
public StringCollection GetGroupMembers(string strDomain, string strGroup, ?)
{
StringCollection groupMemebers = new StringCollection();
try
{
DirectoryEntry ent = new DirectoryEntry(_path);
DirectorySearcher srch = new DirectorySearcher("(CN=" + strGroup + ")");
SearchResultCollection coll = srch.FindAll();
foreach (SearchResult rs in coll)
{
ResultPropertyCollection resultPropColl = rs.Properties;
foreach (Object memberColl in resultPropColl["member"])
{
DirectoryEntry gpMemberEntry = new DirectoryEntry("LDAP://" + memberColl);
System.DirectoryServices.P ropertyCol lection userProps = gpMemberEntry.Properties;
object obVal = userProps["sAMAccountName" ].Value;
if (null != obVal)
{
groupMemebers.Add(obVal.To String());
}
}
}
}
catch (Exception ex)
{
Trace.Write(ex.Message);
}
return groupMemebers;
}
string fullname = System.Security.Principal.
string[] parts = fullname.Split('\\');
string sDomain = parts[0];
string sUser = parts[1];
string sGroup = "gl ca corporate data";
StringCollection groupMembers = this.GetGroupMembers(sDoma
I have a function that gets group members
public StringCollection GetGroupMembers(string strDomain, string strGroup, ?)
{
StringCollection groupMemebers = new StringCollection();
try
{
DirectoryEntry ent = new DirectoryEntry(_path);
DirectorySearcher srch = new DirectorySearcher("(CN=" + strGroup + ")");
SearchResultCollection coll = srch.FindAll();
foreach (SearchResult rs in coll)
{
ResultPropertyCollection resultPropColl = rs.Properties;
foreach (Object memberColl in resultPropColl["member"])
{
DirectoryEntry gpMemberEntry = new DirectoryEntry("LDAP://" + memberColl);
System.DirectoryServices.P
object obVal = userProps["sAMAccountName"
if (null != obVal)
{
groupMemebers.Add(obVal.To
}
}
}
}
catch (Exception ex)
{
Trace.Write(ex.Message);
}
return groupMemebers;
}
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.