我使用此代码来获取当前用户的组.但我想手动给用户,然后得到他的组.我怎样才能做到这一点?
using System.Security.Principal;
public ArrayList Groups()
{
ArrayList groups = new ArrayList();
foreach (IdentityReference group in System.Web.HttpContext.Current.Request.LogonUserIdentity.Groups)
{
groups.Add(group.Translate(typeof(NTAccount)).ToString());
}
return groups;
}
Run Code Online (Sandbox Code Playgroud) 我想找到用户所在的组列表.我从http://www.codeproject.com/KB/system/everythingInAD.aspx尝试了几个解决方案 但没有结果.
这段代码给我一个"真实",表示LDAP正在运行:
public static bool Exists(string objectPath)
{
bool found = false;
if (DirectoryEntry.Exists("LDAP://" + objectPath))
found = true;
return found;
}
Run Code Online (Sandbox Code Playgroud)
谢谢,
更新1:
public ArrayList Groups(string userDn, bool recursive)
{
ArrayList groupMemberships = new ArrayList();
return AttributeValuesMultiString("memberOf", "LDAP-Server",
groupMemberships, recursive);
}
public ArrayList AttributeValuesMultiString(string attributeName,
string objectDn, ArrayList valuesCollection, bool recursive)
{
DirectoryEntry ent = new DirectoryEntry(objectDn);
PropertyValueCollection ValueCollection = ent.Properties[attributeName];
IEnumerator en = ValueCollection.GetEnumerator();
while (en.MoveNext())
{
if (en.Current != null)
{
if (!valuesCollection.Contains(en.Current.ToString()))
{ …
Run Code Online (Sandbox Code Playgroud)