微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

确定WindowsIdentity实例的嵌套组

假设我有一个WindowsIdentity的实例,并希望获得它是其成员的组。 我使用下面的代码获取列表:

WindowsIdentity identity = null; // get identity here identity.Groups.Translate(typeof(NTAccount)).Select(x => x.Value);

我得到这样的东西:

"BUILTIN\Administrators" "BUILTIN\Users" "NT AUTHORITY\INteraCTIVE" "CONSOLE logoN"

我有一个以BUILTIN\Administrators作为其成员的本地组(例如MYSPECIALGROUP )。 上面的示例中不返回MYSPECIALGROUP 。 我如何获得包括嵌套组的所有组?

拦截FILESytemCall进行删除

在ASP.NET中下载文件(通过服务器),同时将其传输给用户

如何在Windows窗体中使用c#创buildF1帮助

如何枚举运行.Net Mono的networking共享?

如何在VB.NET中切换Caps Lock?

C#中的“MoveFile”function(重启后删除文件

Linux单声道等效的.NET Windows服务

如何创build无法正常终止或停止的Windows服务

使用安装程序更新Windows .net程序

如何保持Windows安装对话框在.NET中popup?

从Active Directory获取用户的组成员身份

正如对这个问题的答案解释, System.DirectoryServices.AccountManagement命名空间是你所需要的:

// get the user identity / roles PrincipalContext pCtx = new PrincipalContext(ContextType.Domain,Settings.Default.Domain,// domain Settings.Default.DomainReadUser,// user to access AD with Settings.Default.DomainReadPass); // password of that user UserPrincipal user = UserPrincipal.FindByIdentity(pCtx,User.Identity.Name.Split('\').Last()); // Windows Auth current user // this will have all of the security groups,even nested ones IEnumerable<Principal> userRoles = user.GetAuthorizationGroups();

由于您似乎在做本地机器用户/组,并且使用您的WindowsIdentity变量,所以您需要将前几行更改为:

PrincipalContext pCtx = new PrincipalContext(ContextType.Machine); UserPrincipal user = UserPrincipal.FindByIdentity(pCtx,identity.Name.Split('\').Last());

另请参阅: 在.NET Framework 3.5中管理目录安全主体

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐