我正在构建一个站点,该站点使用当前用户的 WindowsIdentity 获取用户信息。我从中获得的主要信息是 ssid。
我按如下方式为当前用户执行此操作
IntPtr logonToken = WindowsIdentity.GetCurrent().Token;
WindowsIdentity windowsId = new WindowsIdentity(logonToken);
string ssid = windowsId.User.ToString();
我现在需要做的是获取域中存在的任意用户名的 ssid,但我没有做到。
我尝试了 WindowsIdentity(string),但它给了我一个 SecurityException
The name provided is not a properly formed account name.
最佳答案
您如何格式化主体?通常它们采用 user@domain.ext
的形式,因此如果您的 AD 在 example.com
上提供主体解析,则用户主体名称 (UPN) 可能如下所示: joe.bloggs@example.com
。 WindowsIdentity(string)
构造函数接受 UPN,而不是旧格式的用户名 EXAMPLE\joe.bloggs
关于c# - 仅使用域和用户名创建 WindowsIdentity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5933643/