我如何比较UserPrincipal与WindowsIdentity
本文关键字:UserPrincipal WindowsIdentity 比较 何比较 | 更新日期: 2023-09-27 18:01:32
当绑定用户到Windows帐户时,我使用UserPrincipal SamAccountName根据这篇文章(绑定保存在数据库中)。然后,在进行登录时,我需要检查这个绑定的用户(从数据库)对登录的Windows帐户,这是用WindowsIdentity对象完成的。
问题是WindowsClient。名称将状态组'SamAccountName而不仅仅是SamAccount?这将是很好的使用组,但UserPrincipal似乎没有返回这个?
那么我应该如何匹配它们呢?我应该只是删除组在WindowsClient。名称或有一种方法来添加它在UserPrincipal?
这里有几个选项:
-
不要只使用
SamAccountName
来比较主体,它们只在单个域中是唯一的,使用SID来代替:UserPrincipal.Sid
和WindowsIdentity.User
-
不要用
WindowsIdentity
获取当前用户,用UserPrincipal.Current
代替