0

我在我的 asp.net mvc 2.0 站点中使用了一个非常简单的 Ldap 查询:

字符串 ldapPath = ConfigReader.LdapPath; 字符串电子邮件地址 = 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;

它在我的 localhost 机器上运行良好。当我在服务器上的 VS2010 中运行它时,它工作正常。部署时它总是返回空结果。

这是我的 web.config:

Visual Studio 中的 Asp.Net 配置选项。设置和注释的完整列表可以在 machine.config.comments 中找到,通常位于 \Windows\Microsoft.Net\Framework\v2.x\Config -->

部分启用 ASP.NET 用来识别传入用户的安全身份验证模式的配置。-->

<!--

--> 部分可以配置如果/当在执行请求期间发生未处理的错误时要做什么。具体来说,它使开发人员能够配置要显示的 html 错误页面来代替错误堆栈跟踪。-->

我在默认应用程序池下运行它。

有人看到问题了吗?这真让我抓狂!

4

1 回答 1

0

好的,所以我忘了补充一点,我已将运行默认应用程序池的用户帐户更改为具有运行 LDAP 查询的身份验证的用户。

于 2010-05-11T00:24:47.413 回答