源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

asp.net Cookie值中文乱码问题解决方法

  • 时间:2022-05-15 17:40 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:asp.net Cookie值中文乱码问题解决方法
cookie里面不能写中文,是由于cookie先天的编码方式造成的。所以需要有一种中间编码来过渡。 URLEncode是最好的选择。 我们以asp.net为例,代码如下: [b]设置Cookie时[/b]:
[u]复制代码[/u] 代码如下:
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)); }
[b]注意[/b]:编码和解码要一致
[u]复制代码[/u] 代码如下:
System.Web.HttpContext.Current.Server.UrlDecode 和 System.Web.HttpContext.Current.Server.UrlEncode System.Web.HttpUtility.UrlDecode 和 System.Web.HttpUtility.UrlEncode
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部