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

查看:23
本文介绍了在 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.

我想要一个包含 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.

我需要放置一些运行时 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.

有人知道我怎么做吗?

推荐答案

Matthew 击败了我,但是是的,请参阅 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天全站免登陆