放在登陸成功的地方:
string key = TextBox1.Text; //用戶名文本框設爲cache關鍵字 string uer = Convert.ToString(Cache[key]); //讀取cache中用戶相應的值 //判斷cache中是否有用戶的信息,如果沒有相關的值,說明用戶未登陸 if (uer == null || uer == String.Empty) { //定義cache過期時間 TimeSpan SessTimeout = new TimeSpan(0, 0, System.Web.HttpContext.Current.Session.Timeout, 0, 0); //第一次登陸的時候插入一個用戶相關的cache值, HttpContext.Current.Cache.Insert(key, key, null, DateTime.MaxValue, SessTimeout, System.Web.Caching.CacheItemPriority.NotRemovable, null); Session["ADMINID"] = TextBox1.Text; Response.Redirect("main.aspx"); } else { //重複登陸 Response.Write("<script>alert('您的賬號已經登陸!');window.location='login.aspx';</script>"); } |