只是记录一下。。一会做项目要用。。。

 

代码
if (Request.Cookies["tp"!= null && Request.Cookies["tp"].Value == "true")   
        {   
            Alert(
"您已经投票过了!");   
            
return;   
        }   
  
  
        HttpCookie cookie 
= new HttpCookie("tp");   
        cookie.Value 
= "true";   
        cookie.Expires 
= DateTime.Now.AddSeconds(10);   
        Response.Cookies.Add(cookie);   
        Alert(
"投票成功!");  

 

 

原理就是:
1、判断cookie中的某个指是否存在,该值表示是否投票过,存在则弹出提示已经投票过,退出执行
2、不存在,可以投票,建立cookie,上面的代码是设置cookie的过期时间是10秒后
   
    这样就只能是10秒以内才能投票一次

相关文章:

  • 2021-11-03
  • 2021-08-07
  • 2021-12-27
  • 2021-12-31
  • 2021-12-02
  • 2021-08-13
  • 2022-12-23
  • 2021-09-19
猜你喜欢
  • 2021-07-16
  • 2022-12-23
  • 2022-12-23
  • 2021-07-31
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案