我正在使用 ASP.Net 4.0 MVC 查询事件目录。我正在尝试获取用户组成员身份的列表并遍历它们。我有一个奇怪的问题。要获取我正在使用的组:
PrincipalSearchResult<Principal> groups = up.GetGroups();
它在本地主机上运行良好,但在移动到 IIS6 时返回一个空集。所以我尝试使用这个:
PrincipalSearchResult<Principal> groups = up.GetAuthorizationGroups();
这在 IIS6 上运行良好,但在本地主机上返回一个空集。这两种方法有什么区别?为什么我可以在 IIS6 中使用,而不能在本地主机上使用?为什么我可以在本地主机上使用另一个,而不能在 IIS6 中使用?
最佳答案
“为什么”部分已经得到解答,但这可能会帮助那些想知道这两种方法之间功能差异的人。来自 MS 文档:
GetGroups - Returns a collection of group objects that specify the groups of which the current principal is a member.
This overloaded method only returns the groups of which the principal is directly a member; no recursive searches are performed.
GetAuthorizationGroups - Returns a collection of principal objects that contains all the authorization groups of which this user is a member. This function only returns groups that are security groups; distribution groups are not returned.
This method searches all groups recursively and returns the groups in which the user is a member. The returned set may also include additional groups that system would consider the user a member of for authorization purposes.
因此 GetGroups
获取用户是其直接 成员的所有 组,GetAuthorizationGroups
获取所有<用户是其直接或间接成员的strong>授权组。
不管它们的命名方式如何,一个都不是另一个的子集。 GetGroups
返回的组可能不是 GetAuthorizationGroups
返回的,反之亦然。
关于c# - UserPrincipal.GetGroups 与 UserPrincipal.GetAuthorizationGroups?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11162008/