Ldap query returns null result when deployed.

Posted by Trey Carroll on Stack Overflow See other posts from Stack Overflow or by Trey Carroll
Published on 2010-05-10T18:55:15Z Indexed on 2010/05/11 0:34 UTC
Read the original article Hit count: 404

Filed under:
|
|
|
|

I'm using a very simple Ldap query in my asp.net mvc 2.0 site:

String ldapPath = ConfigReader.LdapPath; String emailAddress = null;

        try
        {

            DirectorySearcher search = new DirectorySearcher(ConfigReader.LdapPath);

            search.Filter = String.Format("(&(objectClass=user)(objectCategory=person)(objectSid={0})) ", securityIdentifierValue);

            // add the mail property to the list of props to retrieve                    
            search.PropertiesToLoad.Add("mail");

            var result = search.FindOne();
            if (result == null)
            {
                throw new Exception("Ldap Query with filter:" + search.Filter.ToString() + " returned a null value (no match found)");
            }

            else
            {
                emailAddress = result.Properties["mail"][0].ToString();
            }
        }
        catch (ArgumentOutOfRangeException aoorEx)
        {
            throw new Exception( "The query could not find an email for this user.");
        }
        catch (Exception ex)
        {
            //_log.Error(string.Format("======!!!!!! ERROR ERROR ERROR !!!!! in LdapLookupUtil.cs getEmailFromLdap Exception: {0}", ex));
            throw ex;
        }
        return emailAddress;

It works fine on my localhost machine. It works fine when I run it in VS2010 on the server. It always returns a null result when deployed.

Here is my web.config:

Asp.Net Configuration option in Visual Studio. A full list of settings and comments can be found in machine.config.comments usually located in \Windows\Microsoft.Net\Framework\v2.x\Config -->

section enables configuration of the security authentication mode used by ASP.NET to identify an incoming user. -->

<!--

--> section enables configuration of what to do if/when an unhandled error occurs during the execution of a request. Specifically, it enables developers to configure html error pages to be displayed in place of a error stack trace. -->

I'm running it under the default app pool.

Does anybody see the problem? This is driving me crazy!

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about mvc