关于cookie读值问题,为什么老是读不到某一个值!!
{
//格式:<ID数><ID数2>,使用"<>"符可使ID数值对比时定位准确
if(RB.SelectedIndex!=-1)//如果有选定项目
{
//----------------------- 投票防作弊 -----------------------
HttpCookie makecookie=new HttpCookie ("SocutVote");//制造cookie
HttpCookie readcookie=Request.Cookies["SocutVote"];//读出cookie
if(readcookie==null)//从未投过票
{
makecookie.Values.Add ("VoteItem","<"+strID+">");
makecookie.Expires=DateTime.Now.AddDays(1);
//makecookie.Path="/";
//Label1.Text ="成功!";
// IPlist.Add(lbShowIP.Text);
// bindIPtoListBox();
//Response.Redirect("result.aspx?ID="+strID);//查看结果
//Response.Redirect("result.aspx?ID="+strID);//查看结果
//Response.Write("<script>window.open('result.aspx?ID="+strID+"',target='_blank');</script>");
}
else
{
strAllItem=readcookie.Values["VoteItem"].ToString ();//读取已投票的项
if(strAllItem.IndexOf("<"+strID+">")==-1)//未投过票
{
makecookie.Values.Add("VoteItem",readcookie.Values["VoteItem"]+"<"+strID+">");
}
else//如果已投过票
{
Response.Redirect("error.aspx");
//Label1.Text="<h5 style='color:red'>出错:您已投过票!</h5>";
//Page.RegisterStartupScript("","<script>alert('你已经投过票了!')</script>");
}
}
Response.Cookies.Add(makecookie);//写入Cookie
//Label1.Visible=false;
//==================================================================================
string strSelect=strContent.Split('|')[Convert.ToInt32 (RB.SelectedValue.ToString())];//当前选中的项目,如“ 2,不错”
int intVote=Convert.ToInt32 (strSelect.Split(',')[0]);//当前投票数+1
int intVoteOK=intVote+1;
string strSelectOK=strSelect.Replace (intVote.ToString (),intVoteOK.ToString ());//更新原投票数,所以期望更新的定位精确,可附带+","
string strUPDATE=strContent.Replace(strSelect,strSelectOK);//得到最终
myData.GetExecuteNonQuery("UPDATE socut_vote SET v_content='"+strUPDATE+"' WHERE v_id="+strID);
}
else//如果没有选中项目
{
Label1.Text ="<h5 style='color:red'>出错:请选择投票项!</h5>";
}
}
如果用//Label1.Text="<h5 style='color:red'>出错:您已投过票!</h5>";这个就会报strAllItem=readcookie.Values["VoteItem"].ToString ();//读取已投票的项这个cookie为空。如果用Response.Redirect("error.aspx");这句就不会有错。而且还能写入cookie用label提示错误就连COOKIE也写不入了。还会删除掉cookie,望大侠们指教!!
相关推荐
java中Servlet Cookie取不到值原因解决办法
主要介绍了java中Servlet Cookie取不到值原因解决办法的相关资料,需要的朋友可以参考下
获取不到cookie值问题[项目代码]
文章探讨了通过document.cookie无法获取某cookie值的问题,指出原因在于该cookie设置了HttpOnly属性。HttpOnly属性为true时,cookie仅通过HTTP请求头传递,无法通过JavaScript访问,从而有效防止XSS攻击和cookie窃取,提升安全性。解决方法建议与后端开发者协商,避免在设置cookie时添加HttpOnly属性,以便JavaScript能够访问。
jQuery获取cookie值及删除cookie用法实例
本文实例讲述了jQuery获取cookie值及删除cookie用法。分享给大家供大家参考,具体如下: cookie在jquery中有指定的cookie操作类,这里先来介绍在使用cookie操作类时的一些问题,然后介绍正确的使用方法。 使用JQuery操作cookie时 发生取的值不正确的问题: 结果发现cookie有四个不同的属性: 名称,内容,域,路径 $.cookie('the_cookie'); // 读取 cookie $.cookie('the_cookie', 'the_value'); // 存储 cookie $.cookie('the_cookie', 'the_value
解决Android webview设置cookie和cookie丢失的问题
主要介绍了解决Android webview设置cookie和cookie丢失的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
js读取cookie方法总结
主要介绍了js读取cookie方法,实例总结了四种常用的读取方法,包含了对cookie数据的分割与遍历操作,是非常实用的技巧,需要的朋友可以参考下


