Cookie可以保存多条记录 [英] Can Cookies save more than one record

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

问题描述

嗨..........!



我想知道Cookie是否可以保存多个记录。

我的意思是说,假设我有一个名为用户的Cookie 它保存用户名和密码和

我保存了一个记录,现在我想保存另一个记录,即另一个用户名和密码。




我可以在同一个Cookie中保存多个记录。如果是,那么,我怎样才能从Cookie中读取所有记录..



在此先感谢.....

Hi..........!

I want to know if a Cookie can save more than one Record.
I mean to say, Suppose I have a Cookie named "Users" it saves UserName and Password and
I have saved one Record, now i want to save another Record i.e another UserName and Password.


Can I save more than one Record in Same Cookie. IF yes, then, How can I read all Records from Cookie..

Thanks in Advance.....

推荐答案

嗨朋友,

主要是在客户端存储有限的字符串值。



Cookie通常是有限的到4096字节,每个站点不能存储超过20个cookie。通过将单个cookie与子键一起使用,您可以使用较少的20个cookie来分配您的站点。此外,单个cookie占用大约50个字符用于开销(到期信息等),加上存储在其中的值的长度,所有这些都计入4096字节的限制。如果您存储五个子密钥而不是五个单独的cookie,则可以节省单独cookie的开销,并且可以节省大约200个字节。



最好使用缓存或会话来将用户名和密码存储为列表。

或者如果你想自己存储在cookie中,你必须选择csv格式。

cookieUName = Name1,Name2,Name3 ..

cookiePassword = Pwd1,Pwd2,Pwd3 ..


同样聪明。



并读取cookie,然后将其拆分为与用户名和密码匹配,然后使用它。





一个问题,为什么你想在单个cookie中存储多个用户名和密码。??

Hi Friend,
Primarily cookies are meant to store limited string values in client side.

Cookies are usually limited to 4096 bytes and you can''t store more than 20 cookies per site. By using a single cookie with subkeys, you use fewer of those 20 cookies that your site is allotted. In addition, a single cookie takes up about 50 characters for overhead (expiration information, and so on), plus the length of the value that you store in it, all of which counts toward the 4096-byte limit. If you store five subkeys instead of five separate cookies, you save the overhead of the separate cookies and can save around 200 bytes.

Better you go with cache or session to store Usernames and Passwords as list.
or else if you want to store in cookies it self you have to opt csv format.
cookieUName=Name1,Name2,Name3..
cookiePassword=Pwd1,Pwd2,Pwd3..

Like wise.

and read the cookie then split it up match the User name and password then use it.


and One question why you want to store multiple usernames and passwords in single cookie.??


你需要阅读< a href =http://msdn.microsoft.com/en-us/library/aa289495(v=vs.71).aspx> ASP.NET中的Cookie基础知识 [ ^ ]

并且还读 cookie的限制 [ ^ ]



在这里,上面两个链接将清除你所有的困惑,你很容易得到你的问题的答案。



- Amit
You do need to read Basics of Cookies in ASP.NET[^]
And also read Limitations of a cookie[^]

Here, above two links will clear all your confusions and you''ll easily get the answer of your question.

--Amit


这篇关于Cookie可以保存多条记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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