When logging on to the system, obtain the cookie and Add 1 to it. Then save the cookie.
if (Request.Cookies["loginCount"] == null){HttpCookie c= new HttpCookie("loginCount"); ;Response.Cookies["loginCount"].Value = "1";Response.Cookies["loginCount"].Expires = DateTime.Now.AddDays(1);Response.Cookies.Add(c);}else{int count = Convert.ToInt32(Request.Cookies["loginCount"].Value) + 1;Response.Cookies["loginCount"].Value = count.ToString();}
If (request. cookies ["usercookie"] = NULL) {httpcookie usercookie = new httpcookie ("usercookie"); usercookie. values ["username"] = userinfo. username. tostring (); usercookie. values ["lastvist"] = datetime. now. tostring (); usercookie. values ["count"] = "1"; usercookie. expires = datetime. now. adddays (30); response. cookies. add (usercookie);} else {int counter = convert. toint32 (request. cookies ["usercookie"] ["count"]) + 1; httpcookie usercookie = new httpcookie ("usercookie"); usercookie. values ["username"] = userinfo. username. tostring (); usercookie. values ["lastvist"] = datetime. now. tostring (); usercookie. values ["count"] = counter. tostring (); usercookie. expires = datetime. now. adddays (30); response. cookies. add (usercookie);} get it from another page // read cookiestring namecookie = request. cookies ["usercookie"] ["username"]; response. write ("username:" + namecookie); string timecookie = request. cookies ["usercookie"] ["lastvist"]; response. write ("<br> upload access time:" + timecookie); string countcookie = request. cookies ["usercookie"] ["count"]; response. write ("<br> Number of visits:" + countcookie );
Prevent repeated logins to the same account
Put it in the place where the login is successful:
String key = textbox1.text; // set the username text box to the cache keyword.
String uer = convert. tostring (Cache [Key]); // read the value of the user in the cache
If (uer = NULL | uer = string. Empty) // checks whether the cache contains user information. If no relevant value exists, it indicates that the user has not logged in.
{
// Define the cache expiration time
Timespan sesstimeout = new timespan (0, 0, system. Web. httpcontext. Current. session. Timeout, 0, 0 );
// Insert a user-related cache value during the first login,
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
{
// Repeat response. Write ("<SCRIPT> alert ('your account has logged in! '); Window. Location = 'login. aspx'; </SCRIPT> ");
}