通过创建 HttpCookie 对象的实例编写 Cookie

通过创建HttpCookie对象的实例编写Cookie

HttpCookiemyCookie=newHttpCookie("UserSettings");
myCookie["Font"]="Arial";
myCookie["Color"]="Blue";
myCookie.Expires=DateTime.Now.AddDays(1d);
Response.Cookies.Add(myCookie);

读取Cookie

if(Request.Cookies["UserSettings"]!=null)
{
stringuserSettings;
if(Request.Cookies["UserSettings"]["Font"]!=null)
{userSettings=Request.Cookies["UserSettings"]["Font"];}
}

向Cookie分配已过去的到期日期

if(Request.Cookies["UserSettings"]!=null)
{
HttpCookiemyCookie=newHttpCookie("UserSettings");
myCookie.Expires=DateTime.Now.AddDays(-1d);
Response.Cookies.Add(myCookie);
}

你可能感兴趣的:(cookie)