我必须找到一种方法,如何使用公司Active Direcotries登录用户,我不确定是否有某种方式连接没有管理员凭据(匿名)-我只需要搜索用户,如果他在那里存在。
我尝试了很多解决方案,但都没有效果。我是AD和ASP.NET的新手(但我以前用Java编程)。
到目前为止,我使用的代码来自MSDN站点:
DirectoryEntry entry = new DirectoryEntry(_path);
try
{
//Bind to the native AdsObject to force authentication.
object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(sAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if (null == result)
{
return false;
}
//Update the new path to the user in the directory.
_path = result.Path;
_filterAttribute = (string)result.Properties["cn"][0];
}
catch (Exception ex)
{
throw new Exception("Error authenticating user. " + ex.Message);
}
return true;其中路径是可变的,链接到LDAP (LDAP:/rootDSE)
主要问题是,如果我与AD连接正确,我就无法跟踪。结果以null结尾,但我确信我使用正确的凭据进行测试。
有人能帮上忙或给你建议吗?
非常感谢
发布于 2013-08-09 12:48:03
你可以检查一下
PrincipalContext
如下所示:
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, myDomainTextBox.Text))
{
// validate the credentials
bool cIsValid = pc.ValidateCredentials(myUserNameTextBox.Text, myPasswordBox.Password);
if (cIsValid)
{
// Do some stuff
}
}https://stackoverflow.com/questions/18146855
复制相似问题