我在 ASP.NET 应用程序中使用 Windows 身份验证。我想知道如何最好地从当前登录的用户获取 objectGuid?
问候,埃吉尔。
建议的解决方案相当昂贵。更好的解决方案是使用 SID 来查找帐户,而不是通过域和用户名进行搜索:
// using System.Security.Principal;
IPrincipal userPrincipal = HttpContext.Current.User;
WindowsIdentity windowsId = userPrincipal.Identity as WindowsIdentity;
if (windowsId != null)
{
SecurityIdentifier sid = windowsId.User;
using(DirectoryEntry userDe = new DirectoryEntry("LDAP://<SID=" + sid.Value + ">"))
{
Guid objectGuid = new Guid(userDe.NativeGuid);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)