开发者

Create WindowsIdentity using just a domain and username

开发者 https://www.devze.com 2023-03-04 18:05 出处:网络
I am building a site that gets user information using the WindowsIdentity of the current user.The main info I get from this is the ssid.

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

I do this for the 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 am failing at, 开发者_Go百科is getting the ssid for any arbitrary username that exists on the domain.

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

The name provided is not a properly formed account name.


How are you formatting the principal? Generally they take the form of user@domain.ext, so if your AD provides principal resolution on say example.com, a user principal name (UPN) may look like: joe.bloggs@example.com. The WindowsIdentity(string) constructor accepts a UPN, not an older format username EXAMPLE\joe.bloggs

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号