通過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");
                }

}

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章