Connection to a secured LDAP (SSL)http://forums.asp.net/t/1547198.aspx/1?Connection+to+a+secured+LDAP+SSL+Tue, 13 Sep 2011 12:23:01 -040015471983784416http://forums.asp.net/p/1547198/3784416.aspx/1?Connection+to+a+secured+LDAP+SSL+Connection to a secured LDAP (SSL) <p>Hi,&nbsp;</p> <p>I can't connect my c# website to a LDAP server over SSL. When using ldap browsers, I can do it (they ask me to manually validate the certificate).</p> <p>When I do it in c#, I receive differents exceptions depending on my tests (unknown error, not operationnal server...)</p> <p>Note: I have no problem when I try to connect to a not SSL connection.<br> <br> If anyone could help me, this server is bindable for tests (ldapv3):&nbsp;<br> server: ldapclient.com&nbsp;<br> port: 389&nbsp;<br> authentication: anonymous<br> <br> or with SSL&nbsp;<br> server: ldapclient.com&nbsp;<br> port: 636&nbsp;<br> authentication: anonymous<br> <br> And there is one of the various codes I try:&nbsp;&nbsp;<br> <br> <br> public byte[] GetRecipientCertificateFromLDAPStore()&nbsp;<br> {&nbsp;<br> <b>SearchResultCollection col;&nbsp;<br> DirectorySearcher searcher = new DirectorySearcher();&nbsp;<br> string[] resultsFields = new string[] { &quot;cn&quot;, &quot;mail&quot;, &quot;usercertificate;binary&quot; };&nbsp;<br> //Pass the IPAddress and the Port of the LDAP Server.&nbsp;<br> string[] textArray1 = new string[] { &quot;LDAP://&quot;, &quot;ldapclient.com&quot;, &quot;:&quot;, &quot;636&quot;, &quot;&quot; };&nbsp;<br> searcher.SearchRoot = new DirectoryEntry(string.Concat(textArray1), null, null, AuthenticationTypes.SecureSocketsLayer);&nbsp;<br> searcher.SearchScope = System.DirectoryServices.SearchScope.Subtree;&nbsp;<br> searcher.PropertiesToLoad.AddRange(resultsFields);&nbsp;<br> searcher.Filter = string.Format(&quot;(&amp;(cn={0})(mail={1}))&quot;, &quot;* *&quot;, &quot;* *&quot;);&nbsp;<br> col = searcher.FindAll();&nbsp;</b><br> <br> <br> X509Certificate2 certificate1 = new X509Certificate2();&nbsp;<br> foreach (SearchResult result1 in col)&nbsp;<br> {&nbsp;<br> IEnumerator enumerator2;&nbsp;<br> try&nbsp;<br> {&nbsp;<br> enumerator2 = result1.GetDirectoryEntry().Properties[&quot;usercertificate;binary&quot;].GetEnumerator();&nbsp;<br> while (enumerator2.MoveNext())&nbsp;<br> {&nbsp;<br> object obj1 = RuntimeHelpers.GetObjectValue(enumerator2.Current);&nbsp;<br> certificate1.Import((byte[])obj1);&nbsp;<br> //Can access different Properties for example:&nbsp;<br> //certificate1.Subject;&nbsp;<br> //certificate1.SerialNumber;&nbsp;<br> //certificate1.Version;&nbsp;<br> //certificate1.NotBefore;&nbsp;<br> //certificate1.NotAfter;&nbsp;<br> //certificate1.Issuer;&nbsp;<br> return certificate1.Export(X509ContentType.Cert);&nbsp;<br> <br> }&nbsp;<br> }&nbsp;<br> catch { }&nbsp;<br> <br> }&nbsp;<br> <br> return null;&nbsp;<br> <br> }</p> <p><br> </p> <p>Thanks for any help!</p> <p>Julien</p> 2010-04-14T11:56:03-04:003784660http://forums.asp.net/p/1547198/3784660.aspx/1?Re+Connection+to+a+secured+LDAP+SSL+Re: Connection to a secured LDAP (SSL) <p>Does anybody succeed to connect to ldapclient.com over SSL in c#?</p> <p>Please help me.</p> <p>Julien</p> 2010-04-14T13:55:30-04:003843460http://forums.asp.net/p/1547198/3843460.aspx/1?Re+Connection+to+a+secured+LDAP+SSL+Re: Connection to a secured LDAP (SSL) <p>Hi Julien,</p> <p>&nbsp;&nbsp;&nbsp;I am also looking&nbsp;for same&nbsp;task to connect to an LDAP server using SSL</p> <p>&nbsp;</p> <p>Have you succeeded in finding this out?</p> <p>&nbsp;</p> <p>Krishna&nbsp;&nbsp;&nbsp;</p> 2010-05-17T15:02:43-04:003889019http://forums.asp.net/p/1547198/3889019.aspx/1?Re+Connection+to+a+secured+LDAP+SSL+Re: Connection to a secured LDAP (SSL) <p>Hi,</p> <p>I'm also trying to conncect to LDAP with SSL. I need it to authenticate users. Somehow I got it working, but there are several things which do not work as I think they should: I cannot use LDAPS:// but only LDAP://, because it results in an unknown error. Anyway the connection is established via port 636 and seems to be encrypted when I look at it in wireshark.</p> <p>In addition the variable AuthenticationType seems to have no effect. The data which is transmitted is encrypted anyway.</p> <p>The final problem is that there is know way to check the certificate. I could only do it seperatly.</p> <p>Does anyone know how to fix any of my problems? Anyway my code works somehow and you can use it if you want to.<br> </p> <p>Here it is:<pre class="prettyprint">private String LDAP_ServerAddress = &quot;ldap.xyz.com&quot;; private String LDAP_BaseDN = &quot;ou=sub,o=xyz.com&quot;; /// &lt;summary&gt; /// This method authenticates a user with his password via LDAP /// &lt;/summary&gt; /// &lt;param name=&quot;user&quot;&gt;User to authenticate&lt;/param&gt; /// &lt;param name=&quot;password&quot;&gt;Users password&lt;/param&gt; /// &lt;returns&gt;Whether user &#43; password is correct&lt;/returns&gt; public Boolean authenticateUser(String user, String password) { //Create a directory entry with port 636 (LDAP SSL) DirectoryEntry objDirEntry = new DirectoryEntry(&quot;LDAP://&quot; &#43; this.LDAP_ServerAddress &#43; &quot;:636/&quot; &#43; this.LDAP_BaseDN); //Add the username, it has to be the complete path objDirEntry.Username = &quot;uid=&quot;&#43;user&#43;&quot;,ou=sub,o=xyz.com&quot;; //Add the users password objDirEntry.Password = password; //Authentication Type seems to have no effect objDirEntry.AuthenticationType = AuthenticationTypes.None; try { //method to test the connection/username/password object nativeObject = objDirEntry.NativeObject; objDirEntry.Close(); } //catch exceptions(timeout, bad username or password) catch (COMException exception) { //errorcode -2147023570 bad username or password if (exception.ErrorCode == -2147023570) return false; // errorcode -2147016646 -&gt; timeout else throw new Exception(&quot;Exception in LDAPConenctor.cs Method: void authenticateUser(): &quot; &#43; exception.ToString(), exception); } return true; }</pre></p> 2010-06-01T10:17:21-04:003966050http://forums.asp.net/p/1547198/3966050.aspx/1?Re+Connection+to+a+secured+LDAP+SSL+Re: Connection to a secured LDAP (SSL) <p>Hi,</p> <p>&nbsp;&nbsp;&nbsp;&nbsp; I have the same problem. And I am using&nbsp;very similar code&nbsp;like yours for the SSL connection. However, it refuses to work for some certificate problem. Apparently the security&nbsp;certificate used by the LDAP server is not trusted by the client. I have&nbsp;imported every certificate into the trusted&nbsp;root store on the client, but the&nbsp;ASP.net application seems not to check against them.&nbsp;Do you know anything about it? How is your testing environment set up? Any suggestion?</p> <p>&nbsp;</p> <p>thanks.</p> <p>&nbsp;</p> <p>zheng&nbsp;</p> 2010-07-09T23:05:01-04:003978277http://forums.asp.net/p/1547198/3978277.aspx/1?Re+Connection+to+a+secured+LDAP+SSL+Re: Connection to a secured LDAP (SSL) <p></p> <pre class="prettyprint">private bool CreateConnection() { try { con = new LdapConnection(new LdapDirectoryIdentifier(ConfigurationSettings.AppSettings[&quot;ServerName&quot;].ToString())); con.SessionOptions.SecureSocketLayer = true; con.SessionOptions.ProtocolVersion = 3; con.SessionOptions.VerifyServerCertificate = new VerifyServerCertificateCallback(ServerCallback); con.Credential = new NetworkCredential(_domainAndUserName, _pwd); con.AuthType = AuthType.Basic; con.Timeout = new TimeSpan(1, 0, 0); return true; } catch (LdapException) { return false; } catch (Exception) { return false; } } public bool ServerCallback(LdapConnection connection, X509Certificate certificate) { ...return true/false; } public bool LDAPSAuthenticate(String username, String pwd) { username = username.Trim(); try { con.Bind(); } catch (LdapException ex) { throw new LdapException(ex.Message); } catch (DirectoryOperationException ex) { throw new DirectoryOperationException(ex.Message); } try { SearchRequest request = new SearchRequest( UsersDN, &quot;(&amp;(objectClass=person)(SAMAccountName=&quot; &#43; username &#43; &quot;))&quot;, System.DirectoryServices.Protocols.SearchScope.Subtree ); SearchResponse response = (SearchResponse)con.SendRequest(request); if (response.Entries.Count == 0) { return false; } else { SearchResultEntry entry = response.Entries[0]; string dn = entry.DistinguishedName; con.Credential = new NetworkCredential(dn, pwd); con.Bind(); return true; } } catch (DirectoryOperationException ex) { throw new DirectoryOperationException(ex.Message); } catch (LdapException ex) { throw new LdapException(ex.Message); } catch (Exception ex) { throw new LdapException(ex.Message); } }</pre> <p><br> </p> <p>I have used the above code and it is working fine for LDAP using SSL. &nbsp;Please let me know if you need more information</p> <p></p> &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;public bool LDAPSAuthenticate(String username, String pwd)&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;username = username.Trim();&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;con.Bind();&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;catch (LdapException ex)&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new LdapException(ex.Message);&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;catch (DirectoryOperationException ex)&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new DirectoryOperationException(ex.Message);&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SearchRequest request = new SearchRequest(&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;UsersDN,&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&quot;(&amp;(objectClass=person)(SAMAccountName=&quot; &#43; username &#43; &quot;))&quot;,&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.DirectoryServices.Protocols.SearchScope.Subtree&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;);&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SearchResponse response = (SearchResponse)con.SendRequest(request);&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (response.Entries.Count == 0)&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SearchResultEntry entry = response.Entries[0];&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;string dn = entry.DistinguishedName;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;con.Credential = new NetworkCredential(dn, pwd);&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;con.Bind();&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return true;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;catch (DirectoryOperationException ex)&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new DirectoryOperationException(ex.Message);&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;catch (LdapException ex)&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new LdapException(ex.Message);&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;catch (Exception ex)&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new LdapException(ex.Message);&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}&lt;/div&gt; <p><br> </p> <p><br> </p> 2010-07-18T02:56:51-04:004190251http://forums.asp.net/p/1547198/4190251.aspx/1?Re+Connection+to+a+secured+LDAP+SSL+Re: Connection to a secured LDAP (SSL) <p>Hi,</p> <p>I am trying to authenticate users through LDAP SSL.</p> <p>As far as i have understood,The different ways to connect to an AD and search is by using a directory entry object or by using a search request object.</p> <p>For LDAP SSL is it just enough to turn the AuthenticateType to SSL?</p> <p>What else should we do to enable SSL?Do we need to import any client certificates?</p> <p>could you please tell me any pre-requisites the client has to do to their AD for LDAPS?</p> <p>I have not really understood the servercall back?Is this used to check if the server has a valid certificate?</p> <p>From the product we just need to communicate to the AD securely,so what are the best ways to do it?</p> <p>Please clarify my doubts on LDAPS.</p> 2010-11-30T12:10:17-05:004429090http://forums.asp.net/p/1547198/4429090.aspx/1?Re+Connection+to+a+secured+LDAP+SSL+Re: Connection to a secured LDAP (SSL) <p>Your code seems to be exactly what I'm trying to do, but when I implement it on my system, it's not working. &nbsp;It fails on the con.Bind() line saying &quot;The LDAP server is unavailable.&quot;</p> <p>The way that I implemented it was I created a form with Server, Port, Username &amp; Password. &nbsp;When a user clicks the button I call the CreateConnection method and then the LDAPSAuthenticate() method.</p> <p>It appears to create the connection object properly. &nbsp;The con object is not null at least. &nbsp;I did notice that the con.SessionOptions.HostName &amp; .DomainName are both null. &nbsp;I'm not sure if they get populated after the Bind method.</p> <p>Everything works great when I use the&nbsp;DirectoryEntry class except I don't know how to ignore the Server Cert Verification, which I believe is what your code is supposed to fix. &nbsp;Any ideas? &nbsp;Thanks a ton!</p> <p>&nbsp;</p> &lt;form method=&quot;post&quot; action=&quot;http://localhost:51723/Default.aspx&quot; id=&quot;form1&quot;&gt; &lt;div class=&quot;aspNetHidden&quot;&gt;&lt;/div&gt; &lt;div class=&quot;aspNetHidden&quot;&gt;&lt;/div&gt; &lt;/form&gt; <p>&nbsp;</p> &lt;div&gt;<span style="font-family:'Times New Roman'; font-size:medium"><br> </span>&lt;/div&gt; 2011-05-23T16:39:33-04:004530989http://forums.asp.net/p/1547198/4530989.aspx/1?Re+Connection+to+a+secured+LDAP+SSL+Re: Connection to a secured LDAP (SSL) &lt;div&gt; <p>This thread is a bit old, but I'm hoping someone might still respond as I am also running into this issue. &nbsp;</p> <p>I tried the LdapConnection method specified above after the DirectorySearcher method failed to connect with SSL. &nbsp;I built a windows forms application that was able to successfully connect, but when I move the code to ASP.NET it fails. &nbsp;I wonder if there is a permission I need to grant to Network Services?</p> <p>Has anyone found a solution to this?&nbsp;</p> &lt;/div&gt; 2011-07-29T16:19:42-04:004531358http://forums.asp.net/p/1547198/4531358.aspx/1?Re+Connection+to+a+secured+LDAP+SSL+Re: Connection to a secured LDAP (SSL) <p>I got it working for me.&nbsp; I just had a bad variable in there.&nbsp;</p> 2011-07-29T22:02:28-04:004595174http://forums.asp.net/p/1547198/4595174.aspx/1?Re+Connection+to+a+secured+LDAP+SSL+Re: Connection to a secured LDAP (SSL) <p>Hi,</p> <p>Can you share the flow / implementation code</p> <p>Thanks for the help</p> 2011-09-13T12:23:01-04:00