您的位置:首页 > 理论基础 > 计算机网络

页面中文参数乱码问题解决,HttpCookie乱码

2013-12-04 09:00 225 查看
1.确定引用 using System.Web;using System.Text;
传递页面:
<a target="_blank" href="news.aspx?sp=<%= Server.UrlEncode("网上公示")%>">

接收页面
<%
string sp = HttpUtility.UrlDecode(Request["sp"], Encoding.GetEncoding("utf-8"));
//.GetEncoding("gb2312")也可
%>

2.发现html页面跳转到aspx页面 的中文参数也乱码,而且不能使用上面的方法
于是我果断传数字了 ,到aspx页面在转换成汉字

HttpCookie乱码:中文要先编码,调用的时候要转码
[b]//赋值Cookie[/b]

HttpCookie cookiegroupname = new HttpCookie("groupname");
cookiegroupname.Value = HttpUtility.UrlEncode("我是汉子");[b]//编码[/b]
HttpContext.Current.Response.Cookies.Add(cookiegroupname);
[b][b]//调用[/b][/b]

string name = HttpUtility.UrlDecode(Request.Cookies["groupname"].Value)[b][b]//转码[/b][/b]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  web 中文参数乱码
相关文章推荐