Cookie (HttpCookie的實例)提供了一種在 Web 應用程序中存儲用戶特定信息的方法例如當用戶訪問您的站點時您可以使用Cookie 存儲用戶首選項或其他信息當該用戶再次訪問您的網站時應用程序便可以檢索以前存儲的信息
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/13379.html