title: Forms Authentication: "The server could not be contacted"
body: <p>I add the following to the web.config of an application that I want to require login for:</p>
  
  <pre><code>&lt;authentication mode="Forms"&gt;
    &lt;forms loginUrl="/forms/Login" name=".ASPXAUTH" timeout="60" slidingExpiration="true"&gt;
    &lt;/forms&gt;
  &lt;/authentication&gt;
  &lt;authorization&gt;
    &lt;deny users="?" /&gt;
  &lt;/authorization&gt;
  </code></pre>
  
  <p>/forms/Login is a centralized application for authenticating apps on the same server.
  It has a simple Authentication class with the following method:</p>
  
  <pre><code>    public static bool AuthenticateUser(String username, String password)
      {
          bool validated = false;
          PrincipalContext pc = new PrincipalContext(ContextType.Domain, "mynet.myad.org", "dc=mynet,dc=myad,dc=org");
          validated = pc.ValidateCredentials(username, password, ContextOptions.Negotiate);
          return validated;
      }
  </code></pre>
  
  <p>This works great most of the time but sometimes it seems to "lock up" and it will throw the following exception:  "The server could not be contacted."  It will continue throwing that exception until I restart the web server, or uninstall/re-install the login application.  (I have tried restarting IIS, but this has no effect on it).</p>
  
  <p>I am fairly certain it is not the AD server as the same login code continues to work on other web servers at the same time. I obviously don't want to have to continuously restart the web server or re-install the login application.</p>
  
  <p>I really have no idea where to begin troubleshooting this.
  Any help on this would be greatly appreciated!  </p>