关于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); 这个问题怎么办啊,扩展方法必须在非泛型静态类中定义 关与Dns.GetHostEntry()得不到主机名的问题 webservice C# .NET的优势、劣势、前景 怎样在.net中用c#编写UI自动化测试的程序? 再问一下很弱的问题! 极度郁闷中,,,,,,,,高人进来~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C #如何判断打印机缺纸? 知道圆心坐标 知道半径 怎么求 圆边的坐标 谁帮我详细解答一下:序列化到低有什么作用?为什么要加序列化这个属性? 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);