views:

81

answers:

1

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!

A: 

OK, so I forgot to add that I have changed the user account running the Default App Pool to a user that has auth to run LDAP queryies.

Trey Carroll