我希望如果用戶在1分鐘內沒有訪問站點1分鐘(意味着瀏覽器閒置1分鐘)。當用戶點擊任何鏈接時,他的會話應該過期,他必須再次提供登錄憑證。如果其他頁面閒置1分鐘,則重定向到登錄c#
登錄頁面:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default3Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Session["id"] = TextBox1.Text;
//Session["pass"] = TextBox2.Text;
Response.Redirect("Default3Logout.aspx");
Session.RemoveAll();
}
}
主頁:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default3Logout : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label2.Text = Session["id"].ToString();
}
protected void Button1_Click(object sender, EventArgs e)
{
//Session.Remove("id"); you wana remove one by one use this.
Session.RemoveAll();
Response.Redirect("Default3Login.aspx");
}
}
http://csharpdotnetfreak.blogspot.com/2008/11/detecting-session-timeout-and-redirect.html – Partha
您應該使用超時值爲1的'Forms Authentication'。 –