//第一种添加Cookie方法
HttpCookie myCookie = new HttpCookie("userrole");
myCookie.Values["a"] = "a";
myCookie.Values[""] = "b";
myCookie.Expires.AddDays(1);
Response.Cookies.Add(myCookie);
//Response.AppendCookie(mycookie);这个也可以添加
//第一种获取Cookie方法
Response.Write(Request.Cookies["userrole"].Values["a"].ToString());//第二种添加Cookie方法
HttpCookie myCookie = new HttpCookie("userrole");
myCookie.Values["a"] = "a";
myCookie.Values["b"] = "b";
myCookie.Expires.AddDays(1);
Response.Cookies.Add(myCookie);
//第二种读取Cookie方法
HttpCookie cookie = Request.Cookies["userrole"];
Response.Write(cookie.Values["a"].ToString());
Response.Write(cookie.Values["b"].ToString());//第三种添加Cookie方法
HttpCookie myCookie = new HttpCookie("userrole");
myCookie.Value = "a";
Response.Cookies.Add(myCookie);
//第三种读取Cookie方法
Response.Write(Request.Cookies["userrole"].Value);//第四种添加Cookie方法
HttpContext.Current.Response.Cookies.Add(new HttpCookie("userrole", "超级管理员"));
Response.Cookies["userrole"].Value = "超级管理员";
HttpCookie cookie = Request.Cookies["userrole"];
Response.Write(cookie.Value);
//第三种读取Cookie方法
Response.Write(Request.Cookies["userrole"].Value);
到此这篇关于.net 添加Cookie的4种方法就介绍到这了。青春,一个被赋予太多憧憬与希望的词汇。在很多人眼里青春如火,燃烧着激情与活力;青春如花,绽放着智慧和希望。但在我的眼里,青春就如一只迷途的鹿,徘徊在人生的十字路口,前路是满布的荆棘与彷徨。更多相关.net 添加Cookie的4种方法内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!