【发布时间】:2014-01-27 17:33:50
【问题描述】:
在根据我的数据库中的表收集 Active Directory 数据时,我需要帮助。我有一个包含用户请求的实体类。每个请求都有来自 System.Web.HttpContext.Current.User.Identity.Name 的用户窗口名称。我的问题是我无法弄清楚如何设置 linq 查询以将 AD 用户名与 AD 的其余部分相关联,这样我就可以在我的表中显示他们的全名而不是他们的用户名。这是我到目前为止所拥有的,任何帮助将不胜感激。
public partial class RequestInfo
{
public int RequestInfoId { get; set; }
public string RequestByUserADId { get; set; }
public System.DateTime RequestDateTime { get; set; }
public string Explanation { get; set; }
public virtual UserInfo UserInfo { get; set; } // where I define my custom roles
}
我可以使用下面的代码查询 AD。我试过Get Active Directory User Information With Windows Authentication in MVC 4,但没有帮助。
using (PrincipalContext context = new PrincipalContext(ContextType.Domain))
using (UserPrincipal user = UserPrincipal.FindByIdentity(context, requestByAdId))
{
return user.DisplayName
}
【问题讨论】:
-
你有他们的活动目录用户名,如果你做了 UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(domain, "youruser");它会让你获得用户主体?
-
是的。我在我的设备上对其进行了测试,我可以看到诸如 DisplayName、EmailAddress 之类的字段。它返回正确的值
标签: asp.net-mvc-4 active-directory directoryservices