Note that there are some explanatory texts on larger screens.

plurals
  1. POasp.net Application identifies user on localhost but not on server without hard coding username / password
    text
    copied!<p>I'm setting up a new asp.net site on IIS8 (windows server 2012). I'm trying to take older code that works on windows server 2008, IIS6. Both are virtual servers.</p> <p>Windows authentication is enabled.</p> <p>Anonymous Authentication is disabled. (tried enabling per some post I read but no change)</p> <p>Getting the user by:</p> <pre><code>string user = System.Web.HttpContext.Current.User.Identity.Name; int separatorIndex = user.LastIndexOf(@"\"); if (separatorIndex != -1 &amp;&amp; separatorIndex &lt; user.Length - 1) { user = user.Substring(separatorIndex + 1); } DirectoryEntry rootEntry = new DirectoryEntry("LDAP://na.xxxxxx.biz"); DirectorySearcher directorySearcher = new DirectorySearcher(rootEntry); directorySearcher.Filter = string.Format("(&amp;(objectClass=user)(objectCategory=user) (sAMAccountName={0}))", user); directorySearcher.PropertiesToLoad.Add("displayName"); var result = directorySearcher.FindOne(); </code></pre> <p>This works great on localhost, returns an error on the server:</p> <blockquote> <p>System.DirectoryServices.DirectoryServicesCOMException (0x80072020): An operations error occurred. at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) at System.DirectoryServices.DirectoryEntry.Bind() at System.DirectoryServices.DirectoryEntry.get_AdsObject() at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne) at System.DirectoryServices.DirectorySearcher.FindOne() at EngApps.App_Code.UserFullName.LookUpDirectory() in e:\inetpub\wwwroot\App_Code\UserFullName.cs:line 45</p> </blockquote> <p>line 45 is the last line I posed above using 'FindOne()'</p> <p>If I hard code my user name and password everything works on the server:</p> <pre><code>rootEntry.Username = user; rootEntry.Password = "xxxxxx"; </code></pre> <p>But I don't need this in the older code base so I'm guessing there is a setting in IIS8. I played around with anonymous authentication a bit and read several post but haven't been able to figure it out yet.</p> <p>Thanks for your help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload