当前位置:编程学习 > C#/ASP.NET >>

asp.net怎么防止刷票呢?

这是JQ代码:
$(function () {
        $('#btn_vote').click(function () {
            var radios = $('input:radio[name="id"]:checked').val();
            if (radios == null) {
                alert("请选择一个");
                return false;
            }
            else {
                //alert(radios);
                $.post("Ajax/LoginHandler.ashx", { "action": "vote", "radio": $('input:radio[name="id"]:checked').val() },
                    function (data, status) {
                        if (status != "success") {
                            return;
                        }
                        else if (data == "success") {
                            alert("投票成功");
                        }
                    }
                )
            }
        });
    });

复制代码
这个是处理的代码 ,如何判断一天只能投票一次呢?比如说 IP+cookies只要能实现投票了没有做过任何设置 再投的话能实现就可以了 ,不管安全不安全
if (action=="vote")
            {

                string voteitems = context.Request["radio"].ToString();
                using (var db = new myExpressDataContext())
                {
                    context.Response.Write("success");
                    SurveyTable su = new SurveyTable();
                    if (voteitems == "25")
                    {
                        su.SurveyContent = "非常好";
                        su.SurveryTime = DateTime.Now;
                        db.SurveyTable.InsertOnSubmit(su);
                        db.SubmitChanges();
                    }
                    else if (voteitems == "26")
                    {
                        su.SurveyContent = "比较好";
                        su.SurveryTime = DateTime.Now;
                        db.SurveyTable.InsertOnSubmit(su);
                        db.SubmitChanges();
                    }
                    else if (voteitems == "27")
                    {
                        su.SurveyContent = "一般般";
                        su.SurveryTime = DateTime.Now;
                        db.SurveyTable.InsertOnSubmit(su);
                        db.SubmitChanges();
                    }
                    else if (voteitems == "28")
                    {
                        su.SurveyContent = "较差";
                        su.SurveryTime = DateTime.Now;
                        db.SurveyTable.InsertOnSubmit(su);
                        db.SubmitChanges();
                    }

                }
            }

复制代码 --------------------编程问答-------------------- 验证码+判断IP。 --------------------编程问答-------------------- 你记录投票者的ip加投票时间,并且在浏览器客户端上记录cookie,每次有投票者进行投票的时候都进行判断检测 --------------------编程问答-------------------- 验证码

然后COOKIE

最严格的:记IP
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,