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吗?
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吗?
相关文章推荐
- Asp.Net MVC anti-forgery token的问题:nameidentifier or identityprovider not present
- 关于在IISserver上执行asp.net Web程序出现以下 “Could not load file or assembly。。。”问题的
- Asp.Net 关于Could not load file or assembly 'Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies.问题的解决方法。
- 关于在IIS服务器上运行asp.net Web程序出现下面 “Could not load file or assembly。。。”问题的
- asp.net和js对cookie的相互操作问题
- IIS错误:•Managed handler is used; however, ASP.NET is not installed or is not installed completely.
- 关于ASP.NET“操作必须使用一个可更新的查询”问题的解决方法
- The service cannot be activated because it does not support ASP.NET compatibility. ASP.NET compatibility is enabled for this application. Turn off ASP.NET compatibility mode in the web.config or add the AspNetCompatibilityRequirements attribute to the ser
- web server is not running asp.net version 1.1问题解决
- asp.net的Web应用报“超时时间已到。在操作完成之前超时时间已过或服务器未响应”问题的解决
- ASP.NET 在IIS 操作Excel时出现的权限问题的解决方案
- Asp.net_解决vs运行报在安装 32 位 Oracle 客户端组件的情况下以 64 位模式运行,将出现此问题的bug方法
- Asp.net内置对象之Cookies(简介/属性方法/基本操作及实例)
- 转:Simple ASP.NET 2.0 Tips and Tricks that You May (or may not) have Heard About (一些简单的、你可能已经知道或者不知道的ASP.NET 2.0技巧)
- ASP.NET 手工绑定数据源时分页操作产生的问题
- 关于在ASP.NET中以DCOM方式操作Excel的几个问题
- ASP.Net下如何解决关于Access数据库“操作必须使用一个可更新的查询”问题
- ASP.NET中StreamReader、FileStream、StreamWriter操作文件编码问题
- ASP和ASP.NET共用Cookies问题