手机
当前位置:查字典教程网 >编程开发 >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下cookies的丢失和中文乱码

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

asp.net下大文件上传知识整理

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

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

asp.net Ajax 安装与卸载方法

asp.net aspnetpager分页统计时与实际不符的解决办法

asp.net WebForm页面间传值方法

ASP.net中md5加密码的方法

asp.net C#检查URL是否有效的方法

精品推荐
分类导航