/// <summary> /// 判断网页是否过期 /// </summary> /// <returns></returns> private bool isPageExpired() { if (Session["TimeStamp"] == null || ViewState["TimeStamp"] == null) return false; else if (Session["TimeStamp"] == ViewState["TimeStamp"]) return true; else return false; }
protected void Page_Load(object sender, EventArgs e) { #region 判断网页是否过期 Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1)); Response.Cache.SetNoStore(); Response.AppendHeader("Pragma", "no-cache"); if (Page.IsPostBack) { if (isPageExpired()) { Response.Redirect("expired.htm"); return; } else { Session["TimeStamp"] = DateTime.Now.ToString(); ViewState["TimeStamp"] = DateTime.Now.ToString(); } } #endregion }
时间: 2024-11-06 22:19:03