手机
当前位置:查字典教程网 >编程开发 >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下大文件上传知识整理

asp.net动态加载自定义控件的方法

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

asp.net实现文件无刷新上传方法汇总

ASP.net中md5加密码的方法

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

asp.net网站防恶意刷新的Cookies与Session解决方法

asp.net通过配置文件连接Access的方法

asp.net发邮件的几种方法汇总

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

精品推荐
分类导航