AD用户验证的问题
public static DirectoryEntry GetDirectoryObject() //连接AD
{
DirectoryEntry entry = new DirectoryEntry("LDAP://gdepb.gov.cn", "", "", AuthenticationTypes.Secure);
return entry;
}
系统登录页面,用户输入用户名和密码,点击登录,然后在AD中搜是否存在该用户名,不存在则“该用户不存在”;存在的话进入本地数据库判断密码是否正确,正确则成功登录。
该怎么做呢? 有没有人做过类似的呢?
[解决办法]
AD是什么东东
[解决办法]
直接windows验证不用做登录
[解决办法]
你现在用的匿名登录吧,IIS里改用windows身份验证
http://www.cnblogs.com/dinglang/archive/2012/06/03/2532664.html
然后代码用Request.LogonUserIdentity.Name即为用户的登录名
[解决办法]
public string GetOU(string username)
{
string result = string.Empty;
PrincipalContext yourDomain = new PrincipalContext(ContextType.Domain);
UserPrincipal user = UserPrincipal.FindByIdentity(yourDomain, username);
if (user != null)
{
DirectoryEntry directoryEntry = (user.GetUnderlyingObject() as DirectoryEntry);
if (directoryEntry != null)
{
string[] directoryEntryPath = directoryEntry.Path.Split(',');
foreach (var splitedPath in directoryEntryPath)
{
string[] eleiments = splitedPath.Split('=');
if (eleiments[0].Trim() == "OU")
{
result = username + "-" + eleiments[1].Trim();
break;
}
}
}
}
return result;
}
[解决办法]
using(DirectoryEntry entry = new DirectoryEntry("LDAP://gdepb.gov.cn", "用户名", "密码", AuthenticationTypes.Secure))
{
//entry.RefreshCache(); //如果失败将抛异常
DirectorySearcher searcher = new DirectorySearcher(entry, "(
[解决办法]
(objectClass=person)(objectClass=user))");
//用户名或邮箱都可以登陆
//"(&(
------解决方案--------------------
(objectClass=person)(objectClass=user))(
[解决办法]
(cn=" + 用户名 + ")(mail=" + 邮箱 + ")))"
SearchResult rs = searcher.FindOne(); //如果未找到将抛异常
return true;
}