成人午夜激情影院,小视频免费在线观看,国产精品夜夜嗨,欧美日韩精品一区二区在线播放

ASP.NET中cookie讀寫方法介紹

2010-08-28 10:55:47來源:西部e網作者:

Cookie (HttpCookie的實例)提供了一種在 Web 應用程序中存儲用戶特定信息的方法。例如,當用戶訪問您的站點時,您可以使用Cookie 存儲用戶首選項或其他信息。當該用戶再次訪問您的網站時,應用程序便可以檢索以前存儲的信息。

ASP.NET中的cookie:創建Cookie方法 (1)

Response.Cookies["userName"].Value = “admin";

Response.Cookies[“userName”].Expires = DateTime.Now.AddDays(1);
//如果不設置失效時間,Cookie信息不會寫到用戶硬盤,瀏覽器關閉將會丟棄。

ASP.NET中的cookie:創建Cookie方法 (2)

HttpCookie aCookie = new HttpCookie(“lastVisit”);

//上一次訪問時間

aCookie.Value = DateTime.Now.ToString();

aCookie.Expires = DateTime.Now.AddDays(1);

Response.Cookies.Add(aCookie);

ASP.NET中的cookie:訪問Cookie方法(1)

if(Request.Cookies["userName"] != null)

Label1.Text = Server.HtmlEncode(Request.Cookies["userName"].Value);

訪問Cookie方法(2)

if(Request.Cookies["userName"] != null) {

HttpCookie aCookie = Request.Cookies["userName"];

Label1.Text = Server.HtmlEncode(aCookie.Value);

}

ASP.NET中的cookie:創建多值Cookie方法 (1)

Response.Cookies["userInfo"]["userName"] = “admin";

Response.Cookies["userInfo"]["lastVisit"] = DateTime.Now.ToString();

Response.Cookies["userInfo"].Expires = DateTime.Now.AddDays(1);

ASP.NET中的cookie:創建多值Cookie方法 (2)

HttpCookie aCookie = new HttpCookie("userInfo");

aCookie.Values["userName"] = “admin";

aCookie.Values["lastVisit"] = DateTime.Now.ToString();

aCookie.Expires = DateTime.Now.AddDays(1);

Response.Cookies.Add(aCookie);

ASP.NET中的cookie:讀取多值Cookie

HttpCookie aCookie = Request.Cookies["userInfo"];

string userName=aCookie.Values[“userName”];

string lastVisit=aCookie.Values[“lastVisit”];

ASP.NET中的cookie:修改和刪除Cookie

不能直接修改或刪除Cookie,只能創建一個新的Cookie,發送到客戶端以實現修改或刪除Cookie。

關鍵詞:ASP.NET

贊助商鏈接:

主站蜘蛛池模板: 沂水县| 香格里拉县| 津市市| 罗甸县| 揭阳市| 增城市| 七台河市| 南涧| 扎囊县| 靖州| 闸北区| 汾西县| 庆云县| 陈巴尔虎旗| 东乡县| 紫阳县| 鄄城县| 岐山县| 澄城县| 衢州市| 富民县| 沙田区| 广宁县| 英超| 梁山县| 宾阳县| 郴州市| 黄平县| 五寨县| 平昌县| 越西县| 绥江县| 岳阳县| 黎城县| 育儿| 苍南县| 缙云县| 筠连县| 涞源县| 石门县| 鹿泉市|