怎样修改cookies 中的值 C#
4 回答
![?](http://img1.sycdn.imooc.com/5458471300017f3702200220-100-100.jpg)
慕田峪9158850
TA贡献1794条经验 获得超7个赞
//修改Cookie案例:
protected void Button3_Click(object sender, EventArgs e)
{
//获取客户端的Cookie对象
HttpCookie cok = Request.Cookies["MyCook"];
if (cok != null)
{
//修改Cookie的两种方法
cok.Values["userid"] = "alter-value";
cok.Values.Set("userid", "alter-value");
//往Cookie里加入新的内容
cok.Values.Set("newid", "newValue");
Response.AppendCookie(cok);
}
}
![?](http://img1.sycdn.imooc.com/54584d9f0001043b02200220-100-100.jpg)
catspeake
TA贡献1111条经验 获得超0个赞
Response.Cookies["xxx"].Value = "值";
读取的时候最好是:
string abc="";
if(Request.Cookies["xxx"]!=null) //注意:这里不用Value
{
abc=Request.Cookies["xxx"].Value;
}
添加回答
举报
0/150
提交
取消