1.创建一个新的cookie,并赋值。 HttpCookie cookie;
cookie=new HttpCookie("user");
cookie.Domain = AppConfig.DomainName;
cookie.Values.Add("Username",username);
cookie.Values.Add("ldapStr",FindUserlist.Table.Rows[0]["ldapStr"].ToString());
Response.AppendCookie(cookie);
2.获取cookie的值 HttpCookie cookie=Request.Cookies["user"];
if(cookie!=null)
{
string username = cookie["Username"];
string ldapStr = cookie["ldapStr"];
} 3、写Cookie 值
HttpCookie myCookie = new HttpCookie("CookieName");
myCookie.Values.Add("CookieItem1","CookieItem1Value");
myCookie.Values.Add("CookieItem2","CookieItem2Value");
myCookie.Expires = DateTime.Now.AddDays(30);
Response.AppendCookie(myCookie);
4、清除Cookie值HttpCookie myCookie = HttpContext.Current.Response.Cookies["CookieObjectName"];
if(myCookie != null)
myCookie.Expires = DateTime.Now;