在cookie中存储多个值 [英] Storing multiple values in cookies
问题描述
我有非常大的网站,该网站使用了大量的饼干。还有约。 14种不同的cookie的存在。我对每个项目不同的Cookie。当用户上网时的网站,他们将在自己的浏览器的cookies 14。我不想这样。
I have very large website which uses a lot of cookies. There are approx. 14 different cookies are there. I have different cookies for each item. When a user surfs the site they will have 14 cookies in their browser. I do not want this.
我要为我的网站,将有14个项目,我可以添加,编辑和删除一个Cookie。我尝试过很多方法,但我不能做到这一点。
I want a single cookie for my site that will have 14 items and I can add,edit and delete them. I tried many ways but I am not able to do this.
我需要把一些运行时间饼干以及饼干中保存的用户名。用户登录后,我要救他们的个人网站地址吧。最后,我希望两个用户名和个人网站地址两者。我想之前保存的用户名,然后当用户进入他的个人网站,然后我将存储的个人站点名称的运行时间。
I need to put some run time cookies as well save the user name in cookie. After the user logs in I want to save their personal site address in it. Eventually I want both the user name and personal site address both. I want to save user name before and then when user goes to his personal site then i will store personal site name run time.
没有任何一个有一个想法,我怎么能这样做呢?
Does any one have an idea how I could do this?
推荐答案
马修打我,但肯定的,看的 ASP.NET饼干概述 ...
Matthew beat me to it, but yes, see the ASP.NET Cookies Overview...
要写入和读取多个键/值一个cookie,它会是这个样子:
To write and read a single cookie with multiple key/values, it would look something like this:
HttpCookie cookie = new HttpCookie("mybigcookie");
cookie.Values.Add("name", name);
cookie.Values.Add("address", address);
//get the values out
string name = Request.Cookies["mybigcookie"]["name"];
string address = Request.Cookies["mybigcookie"]["address"];
这篇关于在cookie中存储多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!