简体   繁体   中英

How do I compare UserPrincipal with WindowsIdentity?

When binding a user to a Windows Account Im using the UserPrincipal SamAccountName according to this post (binding saved in database). Then when doing a login I need to check this binded user(from database) against the loggedin Windows Account and this is done with a WindowsIdentity objeckt.

The problem is that WindowsClient.Name will state Group\\SamAccountName instead of just the SamAccount? It would be good to use the group but the UserPrincipal does not seem to return this?

So how should I match thay to? Should I just remove the Group in WindowsClient.Name or is there a way to add it in the UserPrincipal?

There are a few options here:

  1. Don't compare principals using SamAccountName only, theyre only unique within a single domain, use SID instead: UserPrincipal.Sid and WindowsIdentity.User

  2. Don't use WindowsIdentity to get the current user, use UserPrincipal.Current instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM