【发布时间】:2011-01-24 12:59:38
【问题描述】:
我想为AccountDomainUsersSid 创建一个安全标识符。问题是我不知道如何获取当前域(即当前用户登录的域)的 sid。
var sid = new SecurityIdentifier(WellKnownSidType.AccountDomainUsersSid, /* what do I write here? */);
【问题讨论】:
我想为AccountDomainUsersSid 创建一个安全标识符。问题是我不知道如何获取当前域(即当前用户登录的域)的 sid。
var sid = new SecurityIdentifier(WellKnownSidType.AccountDomainUsersSid, /* what do I write here? */);
【问题讨论】:
SecurityIdentifier 有一个 AccountDomainSid 属性。
WindowsIdentity 的 User 属性是一个安全标识符。
WindowsIdentity 具有返回当前 WindowsIdentity 的 GetCurrent() 方法。
所以这会写出当前用户的AccountDomainSid
WindowsIdentity id = WindowsIdentity.GetCurrent();
Console.WriteLine(id.User.AccountDomainSid);
【讨论】: