.net 添加Cookie的4种方法
//第一种添加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);