title: ASP .net forms authentication very slow on first login
body: <p>I have a web application (.net 4.0) with forms authentication (username and password).  I have been trying to track down an issue with a slow login, and have come to the conclusion that on the initial login the page takes anywhere from 20-50seconds to login, and each subsequent logins (logoff and log back in) take an average of 3 seconds.  What is causing this to take so long on an initial login?  Most users will only log into the site once a day, so this seems like the site is slow, when in actuality it appears to be just the initial login.</p>
  
  <pre><code> &lt;asp:Login ID="Login1"
     CssClass="login"
     runat="server"
     InstructionText="Please enter your information."
     CheckBoxStyle - CssClass="loginRememberMe"
     RememberMeText="Remember Me"
     width="300px"
     Height="150px"
     onloggingin="Login1_LoggingIn"
     onauthenticate="Login1_Authenticate"&gt;
  
     &lt;TitleTextStyle CssClass="loginHeader" /&gt; 
     &lt;TextBoxStyle CssClass="loginInput" /&gt;
     &lt;LoginButtonStyle CssClass="loginButton" /&gt;
     &lt;InstructionTextStyle Font - Italic="True" ForeColor="Black" / &gt;
  
   &lt;/asp:Login&gt;
  
  
  protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
  {
      Login login = (Login)loginview1.FindControl("Login1");
      MembershipProvider prov = Membership.Providers["AspNetSqlMembershipProvider"];
      if (prov.ValidateUser(login.UserName, login.Password))
      {
          e.Authenticated = true;
  
          AuthenticatedUser.ConnectionString = "PortalConnectionString";
          AuditUserLogin(login.UserName, true);
  
      }
      else
      {
          AuditUserLogin(login.UserName, false);
          e.Authenticated = false;
      }
  }
  
  private void AuditUserLogin(string Username, bool Authenticated)
  {
      AuditLog.LogUserLoginAttempt(Username, Authenticated, getIP());
  }
  
  protected void Login1_LoggingIn(object sender, LoginCancelEventArgs e)
  {
    //todo
  }
  </code></pre>