title: MVC4 Forms Authentication against AD
body: <p>I am trying to setup an intranet MVC app that authenticates against our company's AD with forms authentication; we do want the user to have to login.  I am getting the following exception when posting to the Login action: "To call this method, the "Membership.Provider" property must be an instance of "ExtendedMembershipProvider"."  Anyone else had this problem?  </p>
  
  <p>Web.config:</p>
  
  <pre><code>&lt;connectionStrings&gt;
    &lt;add name="ADConnectionString" connectionString="LDAP://example.domain.com/DC=example,DC=domain,DC=com"/&gt;
  &lt;/connectionStrings&gt;
  &lt;appSettings&gt;
    &lt;add key="enableSimpleMembership" value="false" /&gt;
  &lt;/appSettings&gt;
  &lt;system.web&gt;
  &lt;authentication mode="Forms"&gt;
    &lt;forms name=".ADAuthCookie" loginUrl="~/Account/Login" timeout="45" slidingExpiration="false" protection="All"/&gt;
  &lt;/authentication&gt;
  &lt;membership defaultProvider="ADMembershipProvider"&gt;
    &lt;providers&gt;
      &lt;clear/&gt;
      &lt;add name="ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider" connectionStringName="ADConnectionString" attributeMapUsername="sAMAccountName"/&gt;
    &lt;/providers&gt;
  &lt;/membership&gt;
  </code></pre>
  
  <p>AccountController:</p>
  
  <pre><code>    [HttpPost]
      [AllowAnonymous]
      [ValidateAntiForgeryToken]
      public ActionResult Login(LoginModel model, string returnUrl)
      {
          //The call to WebSecurity.Login is what throws
          if (ModelState.IsValid &amp;&amp; WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
          {
              return RedirectToLocal(returnUrl);
          }
  
          // If we got this far, something failed, redisplay form
          ModelState.AddModelError("", "The user name or password provided is incorrect.");
          return View(model);
      }
  </code></pre>