我在使用Windows身份验证的ASP.NET应用程序中.
我正在使用HttpContext.Current.User.Identity.Name来获取当前经过身份验证的用户的用户名,该用户以DOMAIN\USERNAME格式获取用户名.这工作正常.
是否有一种简单的方法可以将其转换为显示名称(例如"Richard Gadsden"),就像XP中我的开始菜单顶部显示的名称一样?
如果必须,我想我可以通过System.DirectoryServices并查询到ADSI,但肯定有更简单的方法吗?
Joe*_*pke 14
现在有一种更简单的方法,使用System.DirectoryServices.AccountManagement
Imports System.DirectoryServices.AccountManagement
...
Dim CurrentUser As UserPrincipal = UserPrincipal.Current
Dim DisplayName As String = CurrentUser.DisplayName
Run Code Online (Sandbox Code Playgroud)
这是有关如何执行此操作的教程:
http://www.youcanlearnseries.com/Programming%20Tips/CSharp/LDAPReader.aspx