关于ASP.NET 的cookie的问题 将客户输入的姓名、性别的信息存储在cookie中,代码怎么写? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 存HttpCookie ckName = new HttpCookie["name"];ckName.Value = "张三";Response.AppendCookie(ckName );HttpCookie ckSex= new HttpCookie["Sex"];ckSex.Value = "男人";Response.AppendCookie(ckSex);取string cookieName="";string cookieSex="";HttpCookie ckn= Request.Cookies["ckName"];cookieName= ckn.Value;HttpCookie cks= Request.Cookies["ckSex"];cookieSex=cks.Value; HttpCookie ckName = new HttpCookie["name"];ckName.Value = "张三";Response.AppendCookie(ckName );难道对于每一个信息,我都要写这三行代码? 用多值Cookie:HttpCookie userCookie = new HttpCookie("UserInfo");userCookie.Values["UserName"] = "登录用户";userCookie.Values["UserMale"] = "男";Response.Cookies.Add(userCookie);读取时:if(Request.Cookies["UserInfo"]!=null){ string userName = Request.Cookies["UserInfo"].Values["UserName"]; string userMale = Request.Cookies["UserInfo"].Values["UserMale"];}高级一点的,将用户信息封装为一个实体类,再将对用户信息的读写操作封装为一个属性或方法通过 HttpContext 类型读写,这样代码的可重用性高一些。 顶三楼的!如果信息多的话,可以先把信息存入HashTable中然后再存入Cookie中! HttpCookie ckName = new HttpCookie["name"];ckName.Value = "张三";Response.AppendCookie(this.textbox1.text);HttpCookie ckSex= new HttpCookie["Sex"];ckSex.Value = "this.textbox2.text";Response.AppendCookie(ckSex); System.Web.HttpCookie newcookie = new HttpCookie("user");newcookie.Values["username"] = "";newcookie.Values["sex"] = "";newcookie.Expires = DateTime.Now.AddDays(15);Response.AppendCookie(newcookie); 类成员:internal与protected类型有何区别呢?为何说可以合并使用? C# 怎么把一個dataGrid。DataSource 的DataTable的所有字段放進一個枚舉類型中 请问null与System.DBNull有何区别与联系? 求助:做一个登录窗体.身份验证问题 如何制作自动更新应用程序 视频倒序播放 c#变量作用域 如何用正则获取一串字符串里的数字 c#.net里static的作用是什么 很简单的listBox问题,HELP xml正由另一进程使用,因此该进程无法访问该文 C# radiobutton 清除选中状态
存
HttpCookie ckName = new HttpCookie["name"];
ckName.Value = "张三";
Response.AppendCookie(ckName );HttpCookie ckSex= new HttpCookie["Sex"];
ckSex.Value = "男人";
Response.AppendCookie(ckSex);取
string cookieName="";
string cookieSex="";
HttpCookie ckn= Request.Cookies["ckName"];
cookieName= ckn.Value;
HttpCookie cks= Request.Cookies["ckSex"];
cookieSex=cks.Value;
ckName.Value = "张三";
Response.AppendCookie(ckName );难道对于每一个信息,我都要写这三行代码?
HttpCookie userCookie = new HttpCookie("UserInfo");
userCookie.Values["UserName"] = "登录用户";
userCookie.Values["UserMale"] = "男";
Response.Cookies.Add(userCookie);
读取时:
if(Request.Cookies["UserInfo"]!=null)
{
string userName = Request.Cookies["UserInfo"].Values["UserName"];
string userMale = Request.Cookies["UserInfo"].Values["UserMale"];
}
高级一点的,将用户信息封装为一个实体类,再将对用户信息的读写操作封装为一个属性或方法
通过 HttpContext 类型读写,这样代码的可重用性高一些。
ckName.Value = "张三";
Response.AppendCookie(this.textbox1.text);HttpCookie ckSex= new HttpCookie["Sex"];
ckSex.Value = "this.textbox2.text";
Response.AppendCookie(ckSex);
newcookie.Values["username"] = "";
newcookie.Values["sex"] = "";
newcookie.Expires = DateTime.Now.AddDays(15);
Response.AppendCookie(newcookie);