我有一个MVC5项目,我需要使用用户的Windows登录进行身份验证。此外,我还会在页面顶部显示已记录的人员姓名。它在本地工作正常但是当我将它上传到服务器时如果显示人员用户名它显示它很好但是当我显示全名时我得到错误。
这是显示用户名的代码,它在本地和服务器上都有效:
<div class="right"> Logged in as <span class="username"><b>@User.Identity.Name</b></span></div>
这是显示用户全名只能在本地工作的代码,但它在服务器上不起作用,我收到错误:
{
var context = new System.DirectoryServices.AccountManagement.PrincipalContext(System.DirectoryServices.AccountManagement.ContextType.Domain);
var principal = System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(context, User.Identity.Name);
}
<div class="right"> Logged in as <span class="username"><b> @principal.GivenName @principal.Surname</b></span></div>
这是我在服务器上遇到的错误:
System.DirectoryServices.Protocols.LdapException: The LDAP server is unavailable.