title: Cannot login to ASP.NET membership in .NET 4.5
body: <p>I created a new solution for a web application based on <strong>MVC4</strong> with ASP.NET and the Razor engine. The project uses the template that has membership. For the moment I am not using external logins due to other requirements.</p>
  
  <p>However, I want to make use of the usual membership where the user creates an account on the site. Never had problems with it. I see the whole Accounts controller and its pages deployed on my application. The solution was originally created with VS.2010 so it has <strong>Simple Membership</strong> not the new ASP.NET Identity but is now using <strong>VS.2013</strong> but I have not migrated it to Identity.</p>
  
  <p>I also used the <strong>.NET 4.0</strong> <em>aspnet_regsql.exe</em> application to populate the SQL Server 2012 database with the membership schema.</p>
  
  <p>Then I created a special "install" view where the default accounts and roles are created on this membership database. The creation went without events and I can see the users, roles and their associations in the membership database. I also took care of setting the IsApproved flag to true prior to updating the user, and that also shows on the Membership table.</p>
  
  <p>However, when I try to login to the site (Account Controller) with ANY of the logins I created with the install view, for all of them I get an error message indicating "Invalid username or password".</p>
  
  <p>I placed a breakpoint on the Account Controller Login() method:</p>
  
  <pre><code>[HttpPost]
  [AllowAnonymous]
  [ValidateAntiForgeryToken]
  public async Task&lt;ActionResult&gt; Login(LoginViewModel model, string returnUrl) {
      if (ModelState.IsValid) {
           var user = await UserManager.FindAsync(model.UserName, model.Password); // &lt;-
           if (user != null) { somthing with redirect }
           else { ModelSTate.AddModelError(....); }
      }
      return View(model);
  }
  </code></pre>
  
  <p>So the breakpoint occurs after every login attempt, I can see the Model State is VALID but the following line (await UserManager.FindAsync) always returns NULL even though the user accounts DO exist.</p>
  
  <p>So what am I missing here? why is it failing to retrieve the user data from the database?</p>
  
  <p>My web.config has this:</p>
  
  <pre><code>&lt;connectionStrings&gt;
      &lt;add name="DefaultConnection" 
       connectionString="Server=.\SQLEXPRESS;Database=MyDatabase;uid=myuser;password=mypw;Application Name=MyWeb;"
  
            providerName="System.Data.SqlClient" /&gt;
  &lt;/connectionStrings&gt;
  &lt;authentication mode="Forms"&gt;
    &lt;forms loginUrl="~/Account/Login" timeout="2880" /&gt;
  &lt;/authentication&gt;
  &lt;membership&gt;
    &lt;providers&gt;
      &lt;clear /&gt;
      &lt;add name="AspNetSqlMembershipProvider" 
           type="System.Web.Security.SqlMembershipProvider" 
           connectionStringName="DefaultConnection" 
           enablePasswordRetrieval="false" 
           enablePasswordReset="true" 
           requiresQuestionAndAnswer="true" 
           requiresUniqueEmail="false" 
           maxInvalidPasswordAttempts="5" 
           minRequiredPasswordLength="6" 
           minRequiredNonalphanumericCharacters="0" 
           passwordAttemptWindow="10" 
           passwordFormat="Hashed"  
           applicationName="/myWeb" /&gt;
    &lt;/providers&gt;
  &lt;/membership&gt;
  &lt;profile enabled="true" defaultProvider="AspNetSqlProfileProvider"&gt;
    &lt;providers&gt;
      &lt;clear /&gt;
      &lt;add name="AspNetSqlProfileProvider" 
           type="System.Web.Profile.SqlProfileProvider" 
           connectionStringName="DefaultConnection" 
           applicationName="/myWeb" /&gt;
    &lt;/providers&gt;
  &lt;/profile&gt;
  &lt;roleManager enabled="true"&gt;
    &lt;providers&gt;
      &lt;clear /&gt;
      &lt;add name="AspNetSqlRoleProvider" 
           type="System.Web.Security.SqlRoleProvider" 
           connectionStringName="DefaultConnection" 
           applicationName="/myWeb" /&gt;
    &lt;/providers&gt;
  &lt;/roleManager&gt;
  </code></pre>
  
  <p>Don't see anything wrong with it. Now, Microsoft had the wonderful idea of removing the Asp.Net Web Configuration tool from Visual Studio 2013 (making ppl less productive) but using the workaround that makes use of IIS Express and the URL I do get the page of Membership configuration but it says it could not connect to the database. However, I use the exact same credentials to administer the database schema using SQL Server Management Studio 2012.</p>
  
  <p>I don't get it... I read some things about "migration to identity" but it is not very clear. Should I use a different membership schema on the database?</p>