c# - 仅使用域和用户名创建 WindowsIdentity

标签 c# asp.net windows-identity

我正在构建一个站点,该站点使用当前用户的 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.comWindowsIdentity(string) 构造函数接受 UPN,而不是旧格式的用户名 EXAMPLE\joe.bloggs

关于c# - 仅使用域和用户名创建 WindowsIdentity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5933643/

相关文章:

c# - Linq to entities 无法识别方法 system.string get_Item

c# - Gridview 的 Jquery 和更新面板不起作用

c# - .Net Core 模拟无法与 Process.Start 一起使用

.net - 如何获取当前 Windows 用户的 *network* 身份,而不是他们的交互式登录身份?

c# - stdcall 调用约定和在 C# 中使用 pinvoke

c# - 类型限制

c# - Xamarin AppCenter Crashes.TrackError 没有显示我在 AppCenter 中期望的详细信息

c# - 'basePage' 类型存在于 ASP1.DLL 和 ASP2.DLL 中?

c# - MVC 6 中的 GetOwinContext

wif - 身份提供者与联合提供者有什么区别?