目录服务组查询随机变化

发布于 2024-07-18 08:39:08 字数 1064 浏览 4 评论 0原文

我在我的 ASP.NET 应用程序中收到异常行为。 我的代码使用目录服务来查找给定的经过身份验证的用户的 AD 组。 代码类似于...

string username = "user";
string domain = "LDAP://DC=domain,DC=com";
DirectorySearcher search = new DirectorySearcher(domain);
search.Filter = "(SAMAccountName=" + username + ")";

然后我查询并获取给定用户的组列表。 问题在于代码将组列表作为字符串列表接收。 在我们最新版本的软件中,我们开始以字节[]的形式接收组列表。

系统将返回字符串,突然返回字节[],然后重新启动后再次返回字符串。

有人有主意吗?

(marc_s) 添加了代码示例:

DirectoryEntry dirEntry = new DirectoryEntry("LDAP://" + ldapSearchBase); 
DirectorySearcher userSearcher = new DirectorySearcher(dirEntry) 
  { SearchScope = SearchScope.Subtree, 
    CacheResults = false, 
    Filter = ("(" + txtLdapSearchNameFilter.Text + "=" + userName + ")")
  }; 

userResult = userSearcher.FindOne(); 
ResultPropertyValueCollection valCol = userResult.Properties["memberOf"]; 

foreach (object val in valCol) 
{ 
    if (val is string) 
    {
        distName = val.ToString();
    } 
    else 
    { 
        distName = enc.GetString((Byte[])val); 
    }
}

I am receiving an unusual behaviour in my asp.net application. I have code that uses Directory Services to find the AD groups for a given, authenticated user. The code goes something like ...

string username = "user";
string domain = "LDAP://DC=domain,DC=com";
DirectorySearcher search = new DirectorySearcher(domain);
search.Filter = "(SAMAccountName=" + username + ")";

And then I query and get the list of groups for the given user. The problem is that the code was receiving the list of groups as a list of strings. With our latest release of the software, we are starting to receive the list of groups as a byte[].

The system will return string, suddenly return byte[] and then with a reboot it returns string again.

Anyone have any ideas?

(marc_s) Added code sample:

DirectoryEntry dirEntry = new DirectoryEntry("LDAP://" + ldapSearchBase); 
DirectorySearcher userSearcher = new DirectorySearcher(dirEntry) 
  { SearchScope = SearchScope.Subtree, 
    CacheResults = false, 
    Filter = ("(" + txtLdapSearchNameFilter.Text + "=" + userName + ")")
  }; 

userResult = userSearcher.FindOne(); 
ResultPropertyValueCollection valCol = userResult.Properties["memberOf"]; 

foreach (object val in valCol) 
{ 
    if (val is string) 
    {
        distName = val.ToString();
    } 
    else 
    { 
        distName = enc.GetString((Byte[])val); 
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文