达明,如狐狸过水;机警,如战场上的将军;和善,如主妇款待客人;简单,呆若木鸡;混沌,如深渊之水。

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

以下存和取都是在不同的页面中,如果是在同一个页面也没必要用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  阅读(648)  评论(3编辑  收藏  举报

身是对象树,心如类般明;对象本无根,类型亦无形。