Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

1 solution

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).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900