views:

398

answers:

3

I am using C# to authenticate users to my app as follows:

LdapConnection connection = null;
       try
       {                
           using (connection = new LdapConnection(Configuration.JonahLdapServer))
           {
               connection.Credential = new NetworkCredential(userName, password, Configuration.JonahDomain);
               connection.AuthType = AuthType.Basic;
               connection.SessionOptions.SecureSocketLayer = true;
               connection.SessionOptions.VerifyServerCertificate = 
                   new VerifyServerCertificateCallback(AlwaysTrustCertificateDelegate);
               connection.Bind();
               return true;
           }
       }

When I run this in VS 2008, it works just fine. However, when I deploy the application to IIS 5.1, it gives me the following stacktrace:

System.DirectoryServices.Protocols.LdapException: The LDAP server is unavailable. System.DirectoryServices.Protocols.LdapConnection.Connect() at System.DirectoryServices.Protocols.LdapConnection.BindHelper(NetworkCredential newCredential, Boolean needSetCredential) at System.DirectoryServices.Protocols.LdapConnection.Bind() at Jonahgroup.Lychee.Presentation.Security.SecurityManager.AuthenticateUser(String userName, String password)

It should be noted that if I run the code without SSL, it works fine on both IIS and VS.

Any help would be appreciated.

A: 

It should be noted that if I run the code without SSL, it works fine on both IIS and VS.

The would imply that the problem is related more to your ssl configuration than anything else, though why you're running this on a windows xp (iis 5.1), which is a desktop-class system, rather than a windows server edition is not clear.

Joel Coehoorn
I do not understand how SSL configurations can come into play here. The secure connection is between the code and the ldap server. As such, IIS should not care about how authentication is done (unless there is a need to configure the ldap settings with IIS, which I am unaware of).
Abdul Basit
+1  A: 

The IIS account does not have access to the certificate store. You can either change the IIS account to run as yourself (not recommended for a production deployment) or grant the current IIS account access to each of your certificates (under c:\Documents And Settings\All Users\Application Data\Microsoft\Crypto\RSA).

Incidentally, I found a similar thread in which the author was able to switch the IIS account to use ASPNET from the IUSR_ account.

http://www.velocityreviews.com/forums/t109404-aspnet-and-ldap.html

Ryan Sweet
A: 

Turns out everything works fine when the application is deployed to an IIS 6.0 server.

Thanks for all those who helped.

Abdul Basit