ASP.NET 中使用 Cookie

作者:vkvi 来源:ITPOW(原创) 日期:2007-8-7
ASP.NET 中的 Cookie 和 ASP 中的 Cookie 是不共享的。

写 Cookie 示例

HttpCookie cookie = new HttpCookie("foo", "123"); //参数为 cookie 名称和值
DateTime dt = new DateTime(2008, 3, 3, 1, 1, 1); //参数为年、月、日、时、分、秒
cookie.Expires = dt; //设置过期时间
Response.SetCookie(cookie); //写 Cookie

不能像 ASP 一样,使用 response.Cookies("foo") = "3" 来设置,ASP.NET 中使用 SetCookie。

ASP.NET 中 Response.Cookies["foo"].Value 是有效的,它是个只读属性。

读 Cookie 示例

Request.Cookies["foo"].Value
相关文章