用C#如何创建、读取cookie:
一、创建cookie,并写入数据:
//创建、写入Cookie
HttpCookie cookie = Request.Cookies["MWS_User"];
if (cookie == null)
{
cookie = new HttpCookie("MWS_User");
}
cookie.Values.Set("UserID", strUserID);
Response.SetCookie(cookie);
二、读取cookie:
HttpCookie cookie = Request.Cookies["MWS_User"];
if (cookie != null && cookie["UserID"].ToString() != "")
{
Response.Write("cookie=" + cookie["UserID"].ToString());
}
三、删除Cookie
Response.Cookies["Cookiename"].Expires = DateTime.Now.AddDays(-1);