这是我的问题。我有一个基于表单的Asp.net应用程序,它使用表单身份验证。我在数据库中有用户,但这些用户也必须在活动目录中。
以下代码是为了检查用户是否在A域中:
DirectoryEntry de = new DirectoryEntry();
de.Path = "LDAP://domainA.com";
de.AuthenticationType = AuthenticationTypes.None;
DirectorySearcher search = new DirectorySearcher(de);
search.Filter = "(SAMAccountName=" + account + ")";
search.PropertiesToLoad.Add("displayName");
SearchResult result = search.FindOne();
这段代码运行良好。问题在于客户端要求域名B也能连接到应用程序。因此创建了以下代码:
DirectoryEntry de = new DirectoryEntry();
de.Path = "LDAP://domainB.com";
de.AuthenticationType = AuthenticationTypes.None;
DirectorySearcher search = new DirectorySearcher(de);
search.Filter = "(SAMAccountName=" + account + ")";
search.PropertiesToLoad.Add("displayName");
SearchResult result = search.FindOne();
由于我的服务器在domainA中,所以这不起作用。有没有办法让我查询domainB,知道服务器在domainA中?我找到了一篇文章说需要为domainA和B建立信任关系,但这些域不应该链接。仅针对此应用程序,它们需要这种功能。
P.S. 我可能忘记解释一个重要细节。domainA和B不在同一网络中。但是domainA可以ping通domainB。