简体   繁体   English

从ASP.NET搜索Active Directory

[英]Searching Active Directory from ASP.NET

I have an asp.net website which searches Active Directory for user details using this code: 我有一个asp.net网站,使用以下代码在Active Directory中搜索用户详细信息:

public static SearchResult GetUserProfileFromAD(string username)
{
    DirectorySearcher searcher = new DirectorySearcher("(&(objectCategory=person)(sAMAccountName=" + username + "))");
    return searcher.FindOne();
}

the website is working great on windows server 2003 and IIS5. 该网站在Windows Server 2003和IIS5上运行良好。 recently i move the website to a new windows server 2008 with IIS7.5 i Added application to iis and conect the website and i get this error: 最近我将网站移动到一个新的Windows Server 2008与IIS7.5我添加了应用程序到iis和conect网站,我收到此错误:

The (&(objectCategory=person)(sAMAccountName=)) search filter is invalid. (&(objectCategory=person)(sAMAccountName=))搜索过滤器无效。 Description: An unhandled exception occurred during the execution of the current web request. 描述:执行当前Web请求期间发生未处理的异常。 Please review the stack trace for more information about the error and where it originated in the code. 请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

Exception Details: System.ArgumentException: The (&(objectCategory=person)(sAMAccountName=)) search filter is invalid. 异常详细信息:System.ArgumentException:(&(objectCategory = person)(sAMAccountName =))搜索过滤器无效。

when i run my website through Visual Studio it works. 当我通过Visual Studio运行我的网站时,它的工作原理。 the problem is only from IIS. 问题只来自IIS。

Can someone help me? 有人能帮我吗?

Your "username" variable is blank, causing your filter to terminate in a equal sign (which is, in fact. invalid) Without knowing more about your setup, it's hard to say. 您的“用户名”变量为空,导致您的过滤器以等号终止(实际上是无效的)在不了解您的设置的情况下,很难说。 But it sounds distinctly like you don't have the authentication set up correctly for the website on your new server - causing whatever routine you have to fill in the username to not get anything back. 但是听起来很明显,就像你没有为新服务器上的网站正确设置身份验证 - 导致你必须填写用户名的任何例程都没有得到任何回报。

The error is clearly because "username" is an empty string. 错误显然是因为“username”是一个空字符串。 This is most likely because you're users are logging into your web-site anonymously. 这很可能是因为您的用户正在匿名登录您的网站。 Please ensure that anonymous access is disabled in IIS. 请确保在IIS中禁用匿名访问。

However, it would be helpful if you can show the code which calls GetUserProfileFromAD . 但是,如果您可以显示调用GetUserProfileFromAD的代码,将会很有帮助。

在我看来,变量用户名没有被填充,如果你说你把它移动到IIS尝试再次检查安全选项,可能还没有配置Windows身份验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM