【发布时间】:2012-01-09 22:55:59
【问题描述】:
我正在尝试找到 here 的代码。
我收到以下编译时错误:
名称“p”在当前上下文中不存在
这是我的代码...有人可以帮忙吗?谢谢。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;
public static List<string> GetGroups()
{
using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain))
{
using (p = Principal.FindByIdentity(ctx, "yourUserName"))
{
var groups = p.GetGroups();
using (groups)
{
foreach (Principal group in groups)
{
Console.WriteLine(group.SamAccountName + "-" + group.DisplayName);
}
}
}
}
}
【问题讨论】:
-
对不起,您使用的代码是我为回答另一个问题而创建的 - 我在那里遇到了这个错误。很抱歉 - 现在已经修复了。感谢您指出这一点!
标签: c# active-directory