怎樣修改cookies 中的值 C#
3 回答

躍然一笑
TA貢獻1826條經驗 獲得超6個贊
//修改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);
}
}

隔江千里
TA貢獻1906條經驗 獲得超10個贊
Response.Cookies["xxx"].Value = "值";
讀取的時候最好是:
string abc="";
if(Request.Cookies["xxx"]!=null) //注意:這里不用Value
{
abc=Request.Cookies["xxx"].Value;
}
- 3 回答
- 0 關注
- 619 瀏覽
添加回答
舉報
0/150
提交
取消