ASP.NET2.0状态管理系列(1) Cookie 原理
Cookies provide a means in Web applications to store user-specific information. For example, when a user visits your site, you can use cookies to store user preferences or other information. When the user visits your Web site another time, the application can retrieve the information it stored earlier.
If you do not set the cookie's expiration, the cookie is created but it is not stored on the user's hard disk. Instead, the cookie is maintained as part of the user's session information. When the user closes the browser, the cookie is discarded. A non-persistent cookie like this is useful for information that needs to be stored for only a short time or that for security reasons should not be written to disk on the client computer. For example, non-persistent cookies are useful if the user is working on a public computer, where you do not want to write the cookie to disk.
cookie内容:
UserNameXUlocalhost/102412174743042994977651536080029949575*
C#代码:
2 Response.Cookies["UserName"].Value = "Tom";
3 Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(1);
2 HttpCookie cokie = Request.Cookies["UserName"];
3 string userName = cokie.Value;
使用cookies传递变量值,登陆页面向客户端写cookies不设定过期日期,接下来的页面就可以获得cookies的值。