创建一个Cookie缓存,进行接口防抖
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("您操作得太快了,休息一下吧!"); }