我在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://")) { Guid objectGuid = new Guid(userDe.NativeGuid); } }