hi,
I have a web app(ASP.net 2.0 VS 2005) where am trying to search for a user details in an LDAP.
am getting an exception"System.DirectoryServices.Protocols.LdapException: The LDAP server is unavailable" in my web app while trying to bind with a LDAP.
surprisingly the same piece of code works when i run my web application in debug mode. and works fine fine when i use this code in Windows application too.
below is the code that is used:
public int AuthenticateUser(string szNetID,string szPassword,out bool bAuthenticated){
int nReturn = 0;
string szFunctionName = "AuthenticateUser()";
bool bEntryFound = false;
string szLDAPSearchFilter = "", szDNForNetID = "";
LdapConnection obLdapConnection = null;
SearchRequest obSearchRequest = null;
SearchResponse obSearchResponse = null;
NetworkCredential obNetworkCredential = null;
LdapDirectoryIdentifier obLdapDirectoryIdentifier = null;
string szLDAPUserPrivDN = "XXXX";
string szLDAPUserPrivDNPassword = "XXXX";
string szLDAPServer = "XXXX";
string szLDAPServerPort = "XXXX";
bAuthenticated = false;
try
{
Response.Write(
"Binding");
obNetworkCredential =
new NetworkCredential(szLDAPUserPrivDN, szLDAPUserPrivDNPassword);
obLdapDirectoryIdentifier =
new LdapDirectoryIdentifier(szLDAPServer + ":" + szLDAPServerPort);
obLdapConnection =
new LdapConnection(obLdapDirectoryIdentifier, obNetworkCredential, AuthType.Basic);
obLdapConnection.Bind();
}
catch (System.DirectoryServices.Protocols.LdapException obException)
{
nReturn = -3;
Response.Write(obException.Message);
}
finally
{
// Perform Cleanup
obNetworkCredential =
null;
obLdapDirectoryIdentifier =
null;
if (null != obLdapConnection)
{
obLdapConnection.Dispose();
obLdapConnection =
null;
}
}
return nReturn;
}
is there any dependency of IIS while accessing LDAP?