仅使用域和用户名创建WindowsIdentity [英] Create WindowsIdentity using just a domain and username

查看:108
本文介绍了仅使用域和用户名创建WindowsIdentity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个使用当前用户的WindowsIdentity获取用户信息的站点.我从中获得的主要信息是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();

我现在要做的就是失败了,要获取域中存在的任意用户名的ssid.

What I need to do now, and am failing at, is getting the ssid for any arbitrary username that exists on the domain.

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

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

提供的名称不是正确的帐户名称.

The name provided is not a properly formed account name.

推荐答案

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

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

这篇关于仅使用域和用户名创建WindowsIdentity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆