ASPNET中的cookie創建Cookie方法 ()
ResponseCookies["userName"]Value = “admin";
ResponseCookies[“userName”]Expires = DateTimeNowAddDays();
//如果不設置失效時間Cookie信息不會寫到用戶硬盤浏覽器關閉將會丟棄
ASPNET中的cookie創建Cookie方法 ()
HttpCookie aCookie = new HttpCookie(“lastVisit”);
//上一次訪問時間
aCookieValue = DateTimeNowToString();
aCookieExpires = DateTimeNowAddDays();
ResponseCookiesAdd(aCookie);
ASPNET中的cookie訪問Cookie方法()
if(RequestCookies["userName"] != null)
LabelText = ServerHtmlEncode(RequestCookies["userName"]Value);
訪問Cookie方法()
if(RequestCookies["userName"] != null) {
HttpCookie aCookie = RequestCookies["userName"];
LabelText = ServerHtmlEncode(aCookieValue);
}
ASPNET中的cookie創建多值Cookie方法 ()
ResponseCookies["userInfo"]["userName"] = “admin";
ResponseCookies["userInfo"]["lastVisit"] = DateTimeNowToString();
ResponseCookies["userInfo"]Expires = DateTimeNowAddDays();
ASPNET中的cookie創建多值Cookie方法 ()
HttpCookie aCookie = new HttpCookie("userInfo");
aCookieValues["userName"] = “admin";
aCookieValues["lastVisit"] = DateTimeNowToString();
aCookieExpires = DateTimeNowAddDays();
ResponseCookiesAdd(aCookie);
ASPNET中的cookie讀取多值Cookie
HttpCookie aCookie = RequestCookies["userInfo"];
string userName=aCookieValues[“userName”];
string lastVisit=aCookieValues[“lastVisit”];
ASPNET中的cookie修改和刪除Cookie
不能直接修改或刪除Cookie只能創建一個新的Cookie發送到客戶端以實現修改或刪除Cookie
From:http://tw.wingwit.com/Article/program/net/201311/14092.html