//写入
string ip = Request.UserHostAddress;
HttpCookie cookie = new HttpCookie("CookieName");
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("name");
sb.Append("#");
sb.Append(id.ToString());
sb.Append("#");
Random rnd = new Random();
int type = rnd.Next(0,9999);
cookie.Values.Add("Value",type.ToString());
cookie.Values.Add("Text",type.ToString());
cookie.Expires = DateTime.MaxValue;
Response.AppendCookie(cookie);
//读取
HttpCookie cookie = Request.Cookies["CookieName"];
int type = int.Parse(cookie.Values["Value"].ToString());
string cookieStr = Functions.DecryptCookie(cookie.Values["Text"].ToString(),type);
string [] myCookie = new String[10];
myCookie = cookieStr.Split('#');
name = myCookie[0];
string id = myCookie[1];
string now = myCookie[2];
string times = myCookie[3];
string ip = myCookie[4];
string seal = myCookie[5];
本文介绍如何在ASP.NET应用程序中使用Cookies进行用户信息的存储与读取,包括设置Cookies的有效期、加密Cookies的内容以及如何解析Cookies中的信息。
912

被折叠的 条评论
为什么被折叠?



