我在我的 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 错误页面来代替错误堆栈跟踪。-->
我在默认应用程序池下运行它。
有人看到问题了吗?这真让我抓狂!