通过Cookie判断用户是否已经投过票

      string UserIP = Request.UserHostAddress.ToString();

        if (Request.Cookies["oldCookie"] != null)
        {
            string userIP = Request.Cookies["oldCookie"].Value.Trim();
            if (UserIP.Trim() == userIP.Trim())
            {
                Pigeon.Logistic.InfoAlert.AlertAndGoUrl("您已经投过票,不能进行重复投票,谢谢您的参与!", "Vote.aspx");
                return;

            }
        }
        else
        {
            HttpCookie cookie = new HttpCookie("oldCookie", UserIP);
            cookie.Expires = DateTime.Now.AddDays(1);
            Response.Cookies.Add(cookie);

            Int32 _count = Pigeon.Base.UserInfoDAL._UserInstance.getQuestionCount(Int32.Parse( Session["_PageIndex"].ToString()) );
            if (_count > 0)
            {
                try
                {
       for (int i = 1; i <= _count; i++)
                    {
                        if (!String.IsNullOrEmpty(Request.Form["radio_" + i]))
                        {
                            Pigeon.Base.UserInfoDAL._UserInstance.EditAnswerCount(Int32.Parse(Request.Form["radio_" + i]));
                        }
                        else
                        {
                            if (String.IsNullOrEmpty(Request.Form["radio_1"]) || String.IsNullOrEmpty(Request.Form["radio_2"]) || String.IsNullOrEmpty(Request.Form["radio_2"]))
                          
                            {
                                Pigeon.Logistic.InfoAlert.AlertAndGoUrl("以上投票项目不可为空,请用户认真填写后进行提交!!!", "Vote.aspx?_pageindex=" + Session["_PageIndex"].ToString());
                            }
                        }
                      
                    }
                   
                    if (!String.IsNullOrEmpty(Session["_PageIndex"].ToString()))
                    {
                        if (Session["_PageIndex"].ToString() == "1" || Session["_PageIndex"].ToString() == "2" || Session["_PageIndex"].ToString() == "3")
                        {
                            if (!String.IsNullOrEmpty(Request.Form["radio_1"]) || !String.IsNullOrEmpty(Request.Form["radio_2"]) || !String.IsNullOrEmpty(Request.Form["radio_2"]))
                            {
                                Panel3.Visible = true;
                            }
                        }
                        else
                        {
                            Pigeon.Base.UserInfoDAL._UserInstance.EditUSerFeeCount(_username);
                            Response.Write("<script>window.location.href='OK.aspx'</script>");
                        }
                    }

                }
                catch
                {
                    Pigeon.Logistic.InfoAlert.AlertAndGoUrl("投票失败,谢谢您的参与!!!", "Vote.aspx");
                }
            }      

 

===================================================================================

          string UserIP = Request.UserHostAddress.ToString();

        if (Request.Cookies["oldCookie"] != null)
        {
            string userIP = Request.Cookies["oldCookie"].Value.Trim();
            if (UserIP.Trim() == userIP.Trim())
            {
                Pigeon.Logistic.InfoAlert.AlertAndGoUrl("您已经投过票,不能进行重复投票,谢谢您的参与!", "Vote.aspx");
                return;

            }
        }
        else
        {
            HttpCookie cookie = new HttpCookie("oldCookie", UserIP);
            cookie.Expires = DateTime.Now.AddDays(1);
            Response.Cookies.Add(cookie);
         
                try
                {
                }
                catch
                {
                    Pigeon.Logistic.InfoAlert.AlertAndGoUrl("投票失败,谢谢您的参与!!!", "Vote.aspx");
                }

}

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值