所以这是我当前的代码:

List<string> rowGroups = GetFileGroups((int)row.Cells["document_security_type"].Value);
bool found = false;
System.Security.Principal.WindowsPrincipal p = new System.Security.Principal.WindowsPrincipal(System.Security.Principal.WindowsIdentity.GetCurrent());

foreach (string group in rowGroups)
{
  if (p.IsInRole(group))
  {
    found = true;
    break;
  }
}


这是几个月前由某人完成的,我很难理解为什么它不起作用。该公司最近刚从一个域名转移到另一个域名。所以我很好奇p.IsInRole(“ String”)函数将使用哪个域控制器。我假设无论计算机使用什么,它都将使用默认的DC。

奇怪的是,运行它的办公室中的计算机可能位于2个单独的域中。在List<string>对象中,我有两个域都可能。因此它可能包含“ domainA \ groupA”,“ domainA \ userB”,domainB \ groupC和/或“ domainB \ userD”之类的项目。

所以我的主要问题是IsInRole函数永远不会返回true。我知道应该,我什至用domainA \ Domain用户对其进行了测试,但仍然返回错误。

有任何想法吗?更改代码是可能的,但不希望这样做。我不是100%我甚至可以编译它...

最佳答案

我必须指出,您实际上是在字符串中正确地转义了'\'字符吗?如在“ domainA \\ groupA”中?

关于c# - WindowsPrincipal.IsInRole()未返回预期结果,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/284500/

10-10 11:58