title: MVC2 Active Directory Authentication
body: <p>I'm trying to add Active Directory authentication to a help desk system that was built years ago. Gradually, we'll be upgrading the whole system. I'm starting by creating an MVC2 application that will host the login, and then my plan is to bring current functionality into the MVC as we also add new features. </p>
  
  <p>But the login is the base of the whole thing. We need auditing, so we need to know who's in the system. </p>
  
  <p>I've read articles, other stackoverflow posts, and followed a couple MS walkthroughs to the letter. I was able to get it working as an ASP website, but when it's an MVC application, I can't seem to get it. The ASP application required adding extensive methods, and everything I read makes it sound like MVC should be much simpler.</p>
  
  <p>Here are my IIS settings and the mods I've made to my web.config:</p>
  
  <p>IIS Authentication</p>
  
  <ul>
  <li>Anonymous: Disabled</li>
  <li>ASP.NET Impersonation: Disabled</li>
  <li>Forms: Enabled</li>
  <li><p>Windows: Disabled</p>
  
  <p>
  
  
  ...
  
  
  
  ...
  
    
      
    <br>
  </p></li>
  </ul>
  
  <p>I keep getting the following error:</p>
  
  <p><code>HTTP Error 401.2 - Unauthorized
  You are not authorized to view this page due to invalid authentication headers.</code></p>
  
  <p>End goal is to authenticate the user at the home page. If they can't be authenticated, force the login. </p>
  
  <p><strong>EDIT: Enabled Anonymous Authentication</strong></p>
  
  <p>I enabled Anonymous Authentication to see if any underlying errors might be the source of the problem. I got the following error:</p>
  
  <p><code>The container specified in the connection string does not exist.</code></p>
  
  <p>It's finding the error in the definition of <code>MyADMembershipProvider</code>.</p>
  
  <pre><code>&lt;add name="MyADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ADConnectionString" /&gt;
  </code></pre>
  
  <p>I changed my connection string to the following:</p>
  
  <p><code>&lt;add name="ADConnectionString" connectionString="LDAP://server.domain.com"/&gt;</code></p>
  
  <p>That did successfully redirect to the login page, but it didn't authenticate me automatically. And when I set <code>Anonymous</code> to <code>Disabled</code> again, I was back to the original error.</p>
  
  <p>I think I'm missing some essential knowledge here that I'm not getting from the materials I'm reading.</p>
  
  <p><strong>EDIT: Authentication not working at all</strong></p>
  
  <p>I thought it might be worth adding that authentication isn't working at all.<code>MembershipService.ValidateUser</code> always returns false.</p>