部署时 Ldap 查询返回 null 结果
我在我的 asp.net mvc 2.0 站点中使用一个非常简单的 Ldap 查询:
String 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;
它在我的本地主机上运行良好。当我在服务器上的VS2010中运行它时,它运行得很好。部署时它始终返回空结果。
这是我的 web.config:
Visual Studio 中的 Asp.Net 配置选项。 设置和注释的完整列表可以在 machine.config.comments 通常位于 \Windows\Microsoft.Net\Framework\v2.x\Config -->
部分启用配置 所采用的安全认证方式 ASP.NET 识别传入用户。 -->
<!--
--> 部分启用配置 如果/当发生未处理的错误时该怎么做 在执行请求期间。具体来说, 它使开发人员能够配置 html 错误页面 显示以代替错误堆栈跟踪。 -->
我在默认应用程序池下运行它。
有人看到问题所在吗?这让我发疯!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,所以我忘记补充一点,我已将运行默认应用程序池的用户帐户更改为有权运行 LDAP 查询的用户。
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.