ASP .net forms authentication very slow on first login

最后都变了- 提交于 2021-01-28 08:04:59

问题


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.

 <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">

   <TitleTextStyle CssClass="loginHeader" /> 
   <TextBoxStyle CssClass="loginInput" />
   <LoginButtonStyle CssClass="loginButton" />
   <InstructionTextStyle Font - Italic="True" ForeColor="Black" / >

 </asp:Login>


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
}

来源:https://stackoverflow.com/questions/12286111/asp-net-forms-authentication-very-slow-on-first-login

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!