1. 新创建一个Cookie缓存
Name:SavePInformation
HttpCookie newCookie = new HttpCookie("request"); newCookie["SavePInformation"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); newCookie.Expires = DateTime.Now.AddDays(1); Response.Cookies.Add(newCookie);
2. 获取名字为“SavePInformation”缓存的值 进行逻辑判断
HttpCookie cookie = Request.Cookies["request"]; var preRequestDate = Convert.ToDateTime(cookie["SavePInformation"]); if ((DateTime.Now - preRequestDate).TotalSeconds < 2) { return ErrorMsg("您操作得太快了,休息一下吧!"); }
标签:防抖,缓存,newCookie,DateTime,Cookie,HttpCookie,SavePInformation From: https://www.cnblogs.com/wzzcc/p/17815131.html