請問該怎樣修改cookies 中的值 C#?
請問該怎樣修改cookies 中的值 C#?
慕碼人8056858
2019-07-09 12:04:26
TA貢獻1806條經驗 獲得超8個贊
//修改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貢獻1934條經驗 獲得超2個贊
Response.Cookies["xxx"].Value = "值";
讀取的時候最好是:
string abc="";
if(Request.Cookies["xxx"]!=null) //注意:這里不用Value
{
abc=Request.Cookies["xxx"].Value;
}
舉報