gpt4 book ai didi

.net - 如何检索用户所属的所有角色(组)?

转载 作者:行者123 更新时间:2023-12-03 10:50:19 25 4
gpt4 key购买 nike

有没有办法获取 Windows 身份验证用户所在的角色列表,而无需通过 WindowsPrincipal.IsInRole 明确检查方法?

最佳答案

WindowsPrincipal.IsInRole只检查用户是否是具有该名称的组的成员; Windows 组是一个角色。您可以从 WindowsIdentity.Groups 获取用户所属组的列表。属性(property)。

您可以获得WindowsIdentity来自您的 WindowsPrincipal :

WindowsIdentity identity = WindowsPrincipal.Identity as WindowsIdentity;

或者您可以从 WindowsIdentity 上的工厂方法中获取它:
WindowsIdentity identity = WindowsIdentity.GetCurrent();
WindowsIdenity.GroupsIdentityReference的合集它只是给你组的 SID。如果您需要组名,则需要翻译 IdentityReferenceNTAccount并获得值(value):
var groupNames = from id in identity.Groups
select id.Translate(typeof(NTAccount)).Value;

关于.net - 如何检索用户所属的所有角色(组)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/762245/

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