我们很难让会话超时在 ASP.NET 4 中工作。我们将超时设置为 720 分钟(12 小时)。我们正在使用表单身份验证。无论我将超时设置为什么,超时都会在大约 20 分钟后发生。我确定我们配置了错误,但我不确定是什么。我在网上查看了几个修复程序(标题等),但似乎没有任何工作。这是我们的配置文件:
<authentication mode="Forms">
<forms loginUrl="~/Login.aspx" name="CAFormsAuth" timeout="720" slidingExpiration="true" defaultUrl="Default.aspx" /> </authentication> <authorization> <!--<allow users="*"/>--> <deny users="?" /> </authorization>
这是我们的登录代码:
try
{
string adLogin = txtUserName.Text;
bool isValid = false;
//Validate User against AD First...
//----------------------------------
try
{
isValid = AuthenticateUser(cboDomains.Text, adLogin, txtPassword.Text);
}
catch (Exception ex)
{
//Should read "Invalid Username or Password"...
//lblError.Text = ex.Message;
lblError.Text = "Invalid User Name or Password.";
return;
}
//Now, See if the user exists in the database.
//---------------------------------------------
db_users user = null;
try
{
user = usrHelp.GetUserByADUserName(cboDomains.Text + @"\" + adLogin);
if (user == null)
{
lblError.Text = "User " + adLogin + " does not exist in the database.";
return;
}
}
catch (Exception ex)
{
ErrorLoggingHelper.LogToSource(Globals.ApplicationName, ex.ToString(), System.Diagnostics.EventLogEntryType.Error);
lblError.Text = "User " + adLogin + " does not exist in the database.";
return;
}
if (isValid)
{
if (chkRemember.Checked)
{
SetCookies();
}
else
{
RemoveCookie();
}
}
else
{
lblError.Text = "Password is not valid";
Telerik.Web.UI.RadAjaxManager.GetCurrent(this.Page).ResponseScripts.Add(String.Format("SetFocus('{0}')", txtPassword.ClientID));
return;
}
Session[Globals.LoggedInUserName] = txtUserName.Text;
Session[Globals.LoggedInUserId] = user.user_id;
Session["CurrentUser"] = user;
FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, false);
}
catch (Exception ex)
{
//deleted error logging code here...
lblError.Text = "Error authenticating user. Please contact the administrator.";
}