以下存和取都是在不同的页面中,如果是在同一个页面也没必要用cookies了。
Test1:
给Cookies赋值:
const string AAA="aaa";
Response.Cookies[AAA].Value = "111;222;333";
取值:
string value = Request.Cookies[AAA].Value; // value为111
Test2:
给Cookies赋值:
const string AAA="aaa";
Response.Cookies[AAA].Value = "111222333";
取值:
string value = Request.Cookies[AAA].Value; // value为111222333
Test3:
给Cookies赋值:
const string AAA="aaa";
Response.Cookies[AAA].Value = "111|222|333";
取值:
string value = Request.Cookies[AAA].Value; // value为111|222|333
/////
//页面a
public partial class a : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Cookies[ConstString.user_right].Value = "ccc;aaa;bbb";
}
}
//页面b
public partial class b : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies[ConstString.user_right] != null)
{
TextBox1.Text = Request.Cookies[ConstString.user_right].Value;
}
}
}
//////
再次重申:
以上存和取都是在不同的页面中,如果是在同一个页面也没必要用cookies了。
看懂了再给回复。
结论:
分号(;)所造成的问题。Cookies中使用了分号(;)为分割符,如果值中又有分号,会出现问题,请大家注意。
这是个BUG吗?
每个人都会经过这个阶段,见到一座山,就想知道山后面是什么。我很想告诉他,可能翻过山后面,你会发现没什么特别。回望之下,可能会觉得这一边更好。 每个人都会坚持自己的信念,在别人看来,是浪费时间,她却觉得很重要。
posted @ 2008-11-07 17:16
amingo 阅读(287)
评论(3) 编辑 收藏 网摘