【发布时间】:2015-06-06 22:08:36
【问题描述】:
在我的应用程序中,我使用以下方法将 AD 用户名传递给它(例如:Domain1\User1)并尝试在 Active Directory 中查找用户所属的组。
public ActionResult Login(string userName)
{
PrincipalContext up = new PrincipalContext(ContextType.Domain);
UserPrincipal users = UserPrincipal.FindByIdentity(up,IdentityType.SamAccountName, userName);
PrincipalSearchResult<Principal> groups = users.GetGroups();
IEnumerable<string> userGroupList = groups.Select(p =>p.SamAccountName);
return userGroupList ;
}
该代码运行良好,但是我猜该代码将无法在有多个域的环境中运行。 例如: 1) 用户尝试使用 (Domain1\User1) 登录,它会通过, 2) 用户尝试使用 (Domain2\User2) 登录,应用程序将尝试在 Domain1 中查找 User2,因为没有这样的Domain1 中的用户将失败。
这是真的吗?如果是,我该如何解决这个问题,使其适用于多个域?
【问题讨论】:
标签: c# .net active-directory active-directory-group