Aviadjo
Aviadjo

Reputation: 655

Searching Active Directory from ASP.NET

I have an asp.net website which searches Active Directory for user details using this code:

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. 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:

The (&(objectCategory=person)(sAMAccountName=)) search filter is invalid. Description: An unhandled exception occurred during the execution of the current web request. 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.

when i run my website through Visual Studio it works. the problem is only from IIS.

Can someone help me?

Upvotes: 0

Views: 1903

Answers (3)

Jorge Alvarado
Jorge Alvarado

Reputation: 2674

Seems to me that the variable username is not being populated, if you say that you moved it to IIS try to check again for the security options, probable Windows Authentication is not configured yet.

Upvotes: 0

RB.
RB.

Reputation: 37222

The error is clearly because "username" is an empty string. This is most likely because you're users are logging into your web-site anonymously. Please ensure that anonymous access is disabled in IIS.

However, it would be helpful if you can show the code which calls GetUserProfileFromAD.

Upvotes: 1

Josh Darnell
Josh Darnell

Reputation: 11433

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.

Upvotes: 1

Related Questions