【问题标题】:Create WindowsIdentity using just a domain and username仅使用域和用户名创建 WindowsIdentity
【发布时间】:2011-05-09 07:03:47
【问题描述】:

我正在构建一个使用当前用户的 WindowsIdentity 获取用户信息的站点。我从中得到的主要信息是 ssid。

我对当前用户执行如下操作

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

我现在需要做的是获取域中存在的任意用户名的 ssid。

我尝试了 WindowsIdentity(string),但这给了我一个 SecurityException

提供的名称不是格式正确的帐户名称。

【问题讨论】:

    标签: c# asp.net windows-identity


    【解决方案1】:

    你是如何格式化主体的?通常它们采用user@domain.ext 的形式,因此如果您的AD 提供example.com 上的主体解析,则用户主体名称(UPN)可能类似于:joe.bloggs@example.comWindowsIdentity(string) 构造函数接受 UPN,而不是旧格式的用户名 EXAMPLE\joe.bloggs

    【讨论】:

    • 哦,好吧..我会试一试,看看会发生什么..谢谢
    • 我遇到了一些麻烦,因为我的 UPN 不是 joe.bloggs@example.com 我使用我的 DirectorySearcher 来查询 userPrincipalName,这是 @example.com 的一个细微变化。很有魅力..谢谢
    • 我只有一个像“DOMAIN\username”这样的字符串,我怎样才能得到 WindowsPrincipal ?
    • 嗨,您找到解决方案了吗?
    猜你喜欢
    • 2013-09-21
    • 2010-11-29
    • 2011-10-28
    • 2020-05-12
    • 1970-01-01
    • 1970-01-01
    • 2021-09-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多