在Cookie中存储多个值 [英] Storing multiple values in cookies

查看:1512
本文介绍了在Cookie中存储多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常大的网站,使用大量的cookie。有约。有14个不同的饼干。我对每个项目有不同的cookie。当用户浏览网站时,他们将在浏览器中有14个Cookie。我不想这样。

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.

我想为我的网站添加一个Cookie,其中包含14个项目,我可以添加,编辑和删除它们。我尝试了很多方法,但我不能这样做。

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.

我需要放置一些运行时cookie,并保存cookie中的用户名。在用户登录后,我想保存其个人网站地址。最终,我想要的用户名和个人网站地址。我想保存用户名之前,然后当用户去他的个人网站,然后我将存储个人网站名称运行时间。

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 Cookie概述 ...

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆