Я пытаюсь подключить текущего пользователя к компьютеру через .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.
Любой способ обойти это или другой способ получить полное имя?