我正在尝试使当前用户通过.net MVC登录到计算机。我可以获取域名,但是现在我想要获取名字和姓氏。 给出域详细信息的代码如下:
string userName = System.Web.HttpContext.Current.Request.LogonUserIdentity.Name;
但是,当我尝试使用以下方法获取名字和姓氏时:
using (PrincipalContext domainContext = new
PrincipalContext(ContextType.Domain))
{
UserPrincipal up =UserPrincipal.FindByIdentity(domainContext,
System.Web.HttpContext.Current.User.Identity.Name);
string agtName = up.Name;
TempData["loginName"] = agtName;
}
Web.Config:
<system.web>
<authentication mode="Windows" />
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
我还添加了参考文献:
System.DirectoryServices.AccountManagement
System.DirectoryServices
查看课程:
<p>@TempData["loginName"]</p>
继续收到此错误:
An exception of type 'System.ArgumentException' occurred in System.DirectoryServices.dll but was not handled in user code
Additional information: The (&(objectCategory=user)(objectClass=user)(|(userPrincipalName=)(distinguishedName=)(name=))) search filter is invalid.
有人为此或以其他方式获得全名吗?