手机
当前位置:查字典教程网 >编程开发 >asp.net教程 >asp.net Cookie值中文乱码问题解决方法
asp.net Cookie值中文乱码问题解决方法
摘要:cookie里面不能写中文,是由于cookie先天的编码方式造成的。所以需要有一种中间编码来过渡。URLEncode是最好的选择。我们以as...

cookie里面不能写中文,是由于cookie先天的编码方式造成的。所以需要有一种中间编码来过渡。 URLEncode是最好的选择。

我们以asp.net为例,代码如下:

设置Cookie时:

复制代码 代码如下:

HttpCookie cookie = new HttpCookie("name", System.Web.HttpContext.Current.Server.UrlEncode("查字典教程网"));

Response.Cookies.Add(cookie);读取Cookie时:

if (Request.Cookies["name"] != null)

{

Response.Write(System.Web.HttpContext.Current.Server.UrlDecode(Request.Cookies["name"].Value));

}

注意:编码和解码要一致

复制代码 代码如下:

System.Web.HttpContext.Current.Server.UrlDecode 和 System.Web.HttpContext.Current.Server.UrlEncode

System.Web.HttpUtility.UrlDecode 和 System.Web.HttpUtility.UrlEncode

【asp.net Cookie值中文乱码问题解决方法】相关文章:

asp.net 2.0多语言网站解决方法

iframe跨域与session失效问题的解决办法

asp.net Ajax 安装与卸载方法

asp.net下cookies的丢失和中文乱码

ASP.net判断上传文件类型的三种有效方法

asp.net 备份和恢复数据库的方法

asp.net 字符串加密解密技术

asp.net WebForm页面间传值方法

silverlight2.0Beta版TextBox输入中文解决方法

asp.net GridView 中增加记录的方法

精品推荐
分类导航