title: How do I get WebSecurity.Login to work?
body: <p>I'm trying to get the default login model for MVC4 working, but out of the box, I don't think I'm doing it right.  This is the default code:</p>
  
  <pre><code>if (WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
  {
      return RedirectToLocal(returnUrl);
  }
  </code></pre>
  
  <p>When I build, run and try to log in, I get the following error:</p>
  
  <pre><code>An exception of type 'System.InvalidOperationException' occurred in WebMatrix.WebData.dll but was not handled in user code
  
  Additional information: To call this method, the "Membership.Provider" property must be an instance of "ExtendedMembershipProvider".
  </code></pre>
  
  <p>I thought it was an issue with my provider resources, but I've installed Entity First Tools 6.0.2, System.web.providers, and Microsoft.aspnet.providers.core and am still getting this issue.  I found some indications, it might be because I'm connecting to a SQL database, but I couldn't find a resolution.</p>
  
  <p>Someone indicated I need to use System.Web.Http instead of System.Web.Mvc, but that wasn't it.</p>
  
  <p>This is my connection string:</p>
  
  <pre><code>&lt;add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Server=servername;Initial Catalog=mercury;Integrated Security=SSPI" /&gt;
  </code></pre>
  
  <p>This is my profile and membership info:</p>
  
  <pre><code>&lt;profile defaultProvider="DefaultProfileProvider"&gt;
    &lt;providers&gt;
      &lt;add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" /&gt;
    &lt;/providers&gt;
  &lt;/profile&gt;
  &lt;membership defaultProvider="DefaultMembershipProvider"&gt;
    &lt;providers&gt;
      &lt;add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" /&gt;
    &lt;/providers&gt;
  &lt;/membership&gt;
  </code></pre>
  
  <p>I read something else indicating I needed to initialize my SimpleMembershipProvier, but I have a custom initializer built to run from application_start so I an seed my database with data:</p>
  
  <pre><code>Database.SetInitializer&lt;UsersContext&gt;(new DatabaseInitializer());
  new UsersContext().UserProfiles.Find(1);
  </code></pre>
  
  <p>My data initializer has this code to initialize my database:</p>
  
  <pre><code>private void SeedMembership()
      {
          WebSecurity.InitializeDatabaseConnection("UsersContext", "UserProfile", "UserId", "UserName", autoCreateTables: true);
      }
  </code></pre>
  
  <p>So, I have no idea where to look at next.</p>