gpt4 book ai didi

c# - Active Directory UserPrincipal.Current.GetGroups() 在本地而不是在 Web 服务器上返回组

转载 作者:行者123 更新时间:2023-11-30 17:58:49 25 4
gpt4 key购买 nike

以下内容在我的本地开发盒上效果很好。但是,当我将它移动到 Web 服务器时,它失败了,甚至不会记录错误:

public static List<string> getAuthorizationGrps(string userName)
{
List<string> grps = new List<string>();

try
{
PrincipalSearchResult<Principal> groups = UserPrincipal.Current.GetGroups();
IEnumerable<string> groupNames = groups.Select(x => x.SamAccountName);
foreach (var name in groupNames)
{
grps.Add(name.ToString());
}
return grps;
}
catch (Exception ex)
{
Log.WriteLog("Error in retriving form data: " + ex.Message);
}
}

我是否必须在网络服务器上设置权限才能查询群组?我可以在本地和 Web 服务器上毫无问题地获取当前用户。

任何想法将不胜感激,我已经为此奋斗了 2 天。

最佳答案

大约 6 个月前,我们遇到了类似的问题。我们的代码调用 UserPrincipal.Current.GetGroups() 并在 foreach 循环中枚举对象。在测试和生产中工作正常,直到一天早上 1 同事在执行代码时一直出现异常。枚举 groupNames 对象开始抛出 IndexOutOfRangeException。一个小时后无法弄清楚出了什么问题,所以我添加了一个 kludge,称为一个进行 ADSI 调用的存储过程,类似于 here 的第二个答案。 .它不是很漂亮,但它从来没有出现过任何问题。

关于c# - Active Directory UserPrincipal.Current.GetGroups() 在本地而不是在 Web 服务器上返回组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11846097/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com