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