问题
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