cookies的创建:
在客户端创建一个username的cookies,其值为gjy,有效期为1天.
方法1:
response.cookies["username"].value="gjy";
response.cookies["username"].expires=datetime.now.adddays(1);
方法2:
system.web.httpcookie newcookie=new httpcookie("username");
newcookie.value="gjy";
newcookie.expires=datetime.now.adddays(1);
response.appendcookie(newcookie);
创建带有子键的cookies:
system.web.httpcookie newcookie=new httpcookie("user");
newcookie.values["username"]="gjy";
newcookie.values["password"]="111";
newcookie.expires=datetime.now.adddays(1);
response.appendcookie(newcookie);
cookies的读取:
无子键读取:
if(request.cookies["username"]!=null)
{
response.write(server.htmlencode(request.cookies["username"].value));
}
有子键读取:
if(request.cookies["user"]!=null)
{
response.write(server.htmlencode(request.cookies["user"]["username"].value));
response.write(server.htmlencode(request.cookies["user"]["password"].value));
}
新闻热点
疑难解答