Asp.net search Active Directory from IIS

feofanovv

New Member
Recently I moved my ASP.NET application from an old server running IIS5 to a new server running IIS7.5.The application gives me an error:\[quote\] 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.\[/quote\]The function that searches AD is:\[code\]public static string Get_AD_User_Email(string username){ try { DirectorySearcher searcher = new DirectorySearcher("(&(objectCategory=person)(sAMAccountName=" + username + "))"); SearchResult result = searcher.FindOne(); if (result != null) { DirectoryEntry employee = result.GetDirectoryEntry(); if (employee.Properties["mail"] != null) { return employee.Properties["mail"].Value.ToString(); } else return "NULL"; } else throw new Exception("ERROR: Problem searching active directory for users."); } catch (Exception ex) { throw ex; } }\[/code\]The weird thing is that on debug in Visual Studio the website is running, only from IIS it's crashes.Can someone help me?
 
Back
Top