1
代碼(在Global.asax中):會話超時 - 如何正確記住我?
void Session_Start(object sender, EventArgs e)
{
// remember me
HttpCookie rememberCookie = HttpContext.Current.Request.Cookies["remember"];
if (rememberCookie != null)
{
if (rememberCookie.Value == "true")
HttpContext.Current.Session.Timeout = 464800;
else
HttpContext.Current.Session.Timeout = 70;
}
else
HttpContext.Current.Session.Timeout = 60;
}
基本上,我想使 「記住我」 使用會話和餅乾。 這是代碼時,當第一次發射在home.aspx.cs
public void _loginFrmSubmit(object sender, EventArgs e)
{
Session["User"] = home_username.Text;
HttpCookie rememberCookie;
//rememberCookie.HttpOnly = true;
if (remember.Checked)
{
rememberCookie = new HttpCookie("remember", "true");
rememberCookie.Expires = DateTime.Now.AddMonths(12);
}
else
{
rememberCookie = new HttpCookie("remember", "false");
rememberCookie.Expires = DateTime.Now.AddDays(1);
}
HttpContext.Current.Response.Cookies.Add(rememberCookie);
Response.Redirect(Request.RawUrl);
}
代碼工作正常登錄。但是我註銷後:
public void _Quit(object sender, EventArgs e)
{
HttpCookie rememberCookie = new HttpCookie("remember");
rememberCookie.Expires = DateTime.Now.AddDays(-1);
Response.Cookies.Add(rememberCookie);
Session.Clear();
Response.Redirect(Request.RawUrl);
}
而且我再次登錄。 session.timeout沒有改變。它遇到第一個超時設置。請幫助我每次註銷並登錄時,會話超時更改。
https://stackoverflow.com/questions/3140341/how-to-create-persistent-cookies-in-asp-net這是一個重複的問題 –
亞倫。 S,你只給我發個問題。我的問題是關於會議。 – David
和那個cookie存儲在哪裏?在會話中,對嗎? –