Hi there,
I’m using ASP.NET 2.0 and C#. I’ve a web form with username and password. Username is loaded automatically by grabbing the user id of the person who is currently logged on to the machine. All user has to do is type their AD password and click on Login button.
After the user succfully logs in, I write a session cookie having two values – username and full name (Given Name and Last Name).
This works on the development machine running IIS 7.5. I can login and write a cookie with both the values. But it doesn’t work on production server running IIS 6.0. I get error - An operations error occurred.
Here is my code:
string AdPath = "LDAP://mydomain:389/OU=Users,DC=com "; ActiveDirectoryValidator adAuth = new ActiveDirectoryValidator(AdPath); if (true == adAuth.IsAuthenticated(domainName, userName, password)) { HttpCookie cookie = Request.Cookies["whoyou"]; if (cookie == null) { cookie = new HttpCookie("whoyou"); cookie["Name"] = userName; DirectorySearcher dssearch = new DirectorySearcher(AdPath); dssearch.Filter = "(sAMAccountName=" + userName + ")"; SearchResult sresult = dssearch.FindOne(); DirectoryEntry dsresult = sresult.GetDirectoryEntry(); cookie["Full Name"] = dsresult.Properties["givenName"][0].ToString() + " " + dsresult.Properties["sn"][0].ToString(); Response.Cookies.Add(cookie); Response.Redirect("display.aspx"); } }
I noticed that I get this error at the following line on IIS 6
SearchResult sresult = dssearch.FindOne();
If I comment out the above line, then I can login and write a session cookie with just the user id. It seems that for some reason on IIS 6 I cannot search directory.
Here is my web.config code:
<?xml version="1.0" encoding="UTF-8"?><configuration><appSettings></appSettings><connectionStrings></connectionStrings><system.web><compilation debug="true" defaultLanguage="c#"><assemblies><add assembly="System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /></assemblies></compilation><authentication mode="Windows"></authentication><authorization><deny users="?" /><allow users="*" /></authorization><identity impersonate="true" /><customErrors mode="Off" /></system.web></configuration>
On IIS 7.5, I’ve ASP.Impersonation and Windows Authentication is enabled.
On IIS 6.0, Integrated Windows Authentication is enabled and Anonymous Access is disabled.
I Googled for An operations error occurred. Nothing was helpful to fix the issue so far.
Any ideas as how to get this working on IIS 6.0?
Please Help. Thanks for your help.
Joe