ASPNET中的cookie创建Cookie方法()
ResponseCookies["userName"]Value=“admin";
ResponseCookies[“userName”]Expires=DateTimeNowAddDays();
//如果不设置失效时间Cookie信息不会写到用户硬盘浏览器关闭将会丢弃
ASPNET中的cookie创建Cookie方法()
HttpCookieaCookie=newHttpCookie(“lastVisit”);
//上一次访问时间
aCookieValue=DateTimeNowToString();
aCookieExpires=DateTimeNowAddDays();
ResponseCookiesAdd(aCookie);
ASPNET中的cookie访问Cookie方法()
if(RequestCookies["userName"]!=null)
LabelText=ServerHtmlEncode(RequestCookies["userName"]Value);
访问Cookie方法()
if(RequestCookies["userName"]!=null){
HttpCookieaCookie=RequestCookies["userName"];
LabelText=ServerHtmlEncode(aCookieValue);
}
ASPNET中的cookie创建多值Cookie方法()
ResponseCookies["userInfo"]["userName"]=“admin";
ResponseCookies["userInfo"]["lastVisit"]=DateTimeNowToString();
ResponseCookies["userInfo"]Expires=DateTimeNowAddDays();
ASPNET中的cookie创建多值Cookie方法()
HttpCookieaCookie=newHttpCookie("userInfo");
aCookieValues["userName"]=“admin";
aCookieValues["lastVisit"]=DateTimeNowToString();
aCookieExpires=DateTimeNowAddDays();
ResponseCookiesAdd(aCookie);
ASPNET中的cookie读取多值Cookie
HttpCookieaCookie=RequestCookies["userInfo"];
stringuserName=aCookieValues[“userName”];
stringlastVisit=aCookieValues[“lastVisit”];
ASPNET中的cookie修改和删除Cookie
不能直接修改或删除Cookie只能创建一个新的Cookie发送到客户端以实现修改或删除Cookie