您的位置:首页 > 编程语言 > ASP

ASP.NET操作Cookies的问题(Bug or Not)

2008-11-07 17:16 309 查看
以下存和取都是在不同的页面中,如果是在同一个页面也没必要用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吗?
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐