C#cookies写入,读取事例
2007-08-17 09:11
302 查看
//写入
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];
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];
相关文章推荐
- c#读取写入文本文件
- C#操作Excel文件(读取Excel,写入Excel)
- C#读取和写入Word
- 使用C#实现读取/写入Excel表
- c#实现写入,读取实现百度搜索框
- C#知识点总结系列:1、C#中Hashtable、Dictionary详解以及写入和读取对比
- C#中Hashtable、Dictionary详解以及写入和读取对比
- c#大文件读取和写入数据库(带进度条的源代码)
- C#尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
- 【转】C#操作Excel文件(读取Excel,写入Excel)
- c#中采用OLEDB方式来读取EXCEL文件和将数据写入EXCEL文件
- [转]C# Excel 创建、打开、读取、写入、保存的一般性代码
- C#操作Excel文件(读取Excel,写入Excel)
- C#在MySQL大量数据下的高效读取、写入详解
- C# 文件操作(上传,下载,读取,写入)
- Java是如何读取和写入浏览器Cookies的
- C#操作Excel文件(读取Excel,写入Excel)
- C#中创建、打开、读取、写入、保存Excel的一般性代码
- get,set ,写入读取cookies--[ASP.NET]
- C#操作Excel文件(读取Excel,写入Excel)