Create WindowsIdentity using only domain and username

I am creating a site that receives user information using the WindowsIdentity of the current user. The main information I get from this is ssid.

I do this for current users as follows

IntPtr logonToken = WindowsIdentity.GetCurrent().Token; WindowsIdentity windowsId = new WindowsIdentity(logonToken); string ssid = windowsId.User.ToString(); 

What I need to do now, and I fail, gets ssid for any arbitrary username that exists in the domain.

I tried WindowsIdentity (string), but that gave me a SecurityException

The specified name is not a correctly formed account name.

+6
source share
1 answer

How do you format a principal? Usually they take the form of user@domain.ext , so if your AD provides basic permission, say example.com , the user principal name (UPN) might look like this: joe.bloggs@example.com . The WindowsIdentity(string) constructor accepts UPN, not the previous username EXAMPLE\joe.bloggs

+4
source

Source: https://habr.com/ru/post/887597/


All Articles