没有合适的资源?快使用搜索试试~ 我知道了~
.net程序开发中,利用Cookie,防止刷新!也可以用做网站访问的计数器!
资源推荐
资源详情
资源评论
//进行投票
protected void Button1_Click(object sender, EventArgs e)
{
//判断指定的IP是否已在本月投过票了,如果已经投过了,则弹出提示对话框
string UserIP = Request.UserHostAddress.ToString( );
int VoteID = Convert.ToInt32(RadioButtonList1.SelectedIndex.ToString( ))+1;
HttpCookie oldCookie=Request.Cookies["userIP"];
if (oldCookie == null)
{
UpdateVote(VoteID);
Response.Write("<script>alert('投票成功,谢谢您的参与!')</script>");
HttpCookie newCookie = new HttpCookie("userIP"); //定义新的Cookie对象
newCookie.Expires = DateTime.Now.AddMonths(1);
//添加新的Cookie变量IPaddress,值为UserIP
newCookie.Values.Add("IPaddress", UserIP);
Response.AppendCookie(newCookie); //将变量写入Cookie文件中
return;
}
else
{
string userIP = oldCookie.Values["IPaddress"];
if (UserIP.Trim( ) == userIP.Trim( ))
{
Response.Write("<script>alert('一个IP地址
一个月内只能投一次票,谢谢您的参与!');history.go(-1);获至宝</script>");
return;
}
else
{
HttpCookie newCookie = new HttpCookie("userIP");
protected void Button1_Click(object sender, EventArgs e)
{
//判断指定的IP是否已在本月投过票了,如果已经投过了,则弹出提示对话框
string UserIP = Request.UserHostAddress.ToString( );
int VoteID = Convert.ToInt32(RadioButtonList1.SelectedIndex.ToString( ))+1;
HttpCookie oldCookie=Request.Cookies["userIP"];
if (oldCookie == null)
{
UpdateVote(VoteID);
Response.Write("<script>alert('投票成功,谢谢您的参与!')</script>");
HttpCookie newCookie = new HttpCookie("userIP"); //定义新的Cookie对象
newCookie.Expires = DateTime.Now.AddMonths(1);
//添加新的Cookie变量IPaddress,值为UserIP
newCookie.Values.Add("IPaddress", UserIP);
Response.AppendCookie(newCookie); //将变量写入Cookie文件中
return;
}
else
{
string userIP = oldCookie.Values["IPaddress"];
if (UserIP.Trim( ) == userIP.Trim( ))
{
Response.Write("<script>alert('一个IP地址
一个月内只能投一次票,谢谢您的参与!');history.go(-1);获至宝</script>");
return;
}
else
{
HttpCookie newCookie = new HttpCookie("userIP");
资源评论
maji7401
- 粉丝: 0
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功