我們很難讓Session Timeout在ASP.NET 4中工作。我們將超時設置爲720分鐘(12小時)。我們使用表單身份驗證。無論我將超時設置爲何時,約20分鐘後都會發生超時。我確定我們配置了錯誤的東西,但我不確定是什麼。我在網上查了幾個修正(頭文件等),但似乎無法獲得任何工作。下面是我們的配置文件:會話超時不起作用ASP.NET 4
<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.";
}
是的,就是這樣。感謝您的迴應... – 2012-07-31 21:55:40
良好的交易。請接受答案,以便其他人可以從問答中獲益。 – Bazinga 2013-12-11 16:01:46