带有登录页面问题的活动目录 [英] active directory with login page issue

查看:74
本文介绍了带有登录页面问题的活动目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hii Frnds


我已通过登录页面实现活动目录
我正在使用此代码.cs

受保护的无效btnLogin_Click(对象发送者,EventArgs e)
{

字符串dominName = string.Empty;
字符串adPath = string.Empty;
字符串userName = txtLoginID.Text.Trim().ToUpper();
字符串strError = string.Empty;
试试
{

foreach(ConfigurationManager.AppSettings.Keys中的字符串键)
{
dominName = key.Contains("DirectoryDomain")吗? ConfigurationManager.AppSettings [key]:dominName;
adPath = key.Contains("DirectoryPath")吗? ConfigurationManager.AppSettings [key]:adPath;
如果(!String.IsNullOrEmpty(dominName)&&!String.IsNullOrEmpty(adPath))
{
if(true == AuthenticateUser(dominName,userName,txtPassword.Text,adPath,out strError))
{
Response.Redirect("WebForm1.aspx");//经过身份验证的用户重定向到default.aspx
}
dominName = string.Empty;
adPath = string.Empty;
如果(String.IsNullOrEmpty(strError))中断;
}

}
如果(!string.IsNullOrEmpty(strError))
{
lblError.Text =无效的用户名或密码!";
}
}
赶上
{

}
终于
{

}

}
公共布尔AuthenticateUser(字符串域,字符串用户名,字符串密码,字符串LdapPath,字符串Errmsg)
{
Errmsg =";
字符串domainAndUsername = domain +"\\" +用户名;
DirectoryEntry条目=新的DirectoryEntry(LdapPath,domainAndUsername,密码);
试试
{
//绑定到本机AdsObject以强制进行身份验证.
对象obj = entry.NativeObject;
DirectorySearcher搜索=新的DirectorySearcher(条目);
search.Filter =(SAMAccountName =" +用户名+)";
search.PropertiesToLoad.Add("cn");
SearchResult结果= search.FindOne();
如果(空==结果)
{
返回false;
}
//更新目录中用户的新路径
LdapPath = result.Path;
字符串_filterAttribute =(String)result.Properties ["cn"] [0];
}
catch(ex ex例外)
{
Errmsg = ex.Message;
返回false;
抛出新的Exception(验证用户身份时出错." + ex.Message);
}
返回true;
}

我在这里得到错误Object obj = entry.NativeObject;

该错误是未知错误0 * 80005000

请向我分享任何想法

Hii Frnds


i am implemented active directory with login page
i am using this code .cs

protected void btnLogin_Click(object sender, EventArgs e)
{

string dominName = string.Empty;
string adPath = string.Empty;
string userName = txtLoginID.Text.Trim().ToUpper();
string strError = string.Empty;
try
{

foreach (string key in ConfigurationManager.AppSettings.Keys)
{
dominName = key.Contains("DirectoryDomain") ? ConfigurationManager.AppSettings[key] : dominName;
adPath = key.Contains("DirectoryPath") ? ConfigurationManager.AppSettings[key] : adPath;
if (!String.IsNullOrEmpty(dominName) && !String.IsNullOrEmpty(adPath))
{
if (true == AuthenticateUser(dominName, userName, txtPassword.Text, adPath, out strError))
{
Response.Redirect("WebForm1.aspx");// Authenticated user redirects to default.aspx
}
dominName = string.Empty;
adPath = string.Empty;
if (String.IsNullOrEmpty(strError)) break;
}

}
if (!string.IsNullOrEmpty(strError))
{
lblError.Text = "Invalid user name or Password!";
}
}
catch
{

}
finally
{

}

}
public bool AuthenticateUser(string domain, string username, string password, string LdapPath, out string Errmsg)
{
Errmsg = "";
string domainAndUsername = domain + "\\" + username;
DirectoryEntry entry = new DirectoryEntry(LdapPath, domainAndUsername, password);
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
LdapPath = result.Path;
string _filterAttribute = (String)result.Properties["cn"][0];
}
catch (Exception ex)
{
Errmsg = ex.Message;
return false;
throw new Exception("Error authenticating user." + ex.Message);
}
return true;
}

i am getting the error here Object obj = entry.NativeObject;

that error is unknown error 0*80005000

please share any idea to me

推荐答案

正是针对LDAP进行身份验证的要点:当调用entry.NativeObject成功时,用户已正确进行身份验证,否则(用户不存在,或密码错误).
Exactly that''s the point with authentication against LDAP: when calling entry.NativeObject succeeds, the user has correctly authenticated, otherwise not (user does not exist, or password is wrong).


这篇关于带有登录页面问题的活动目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆