System.Text.Encoding enc = System.Text.Encoding.GetEncoding("gb2312");
string cookie = Request.Cookies["YourCookieName"].Value;
string cookieValue = HttpUtility.UrlDecode( cookie,enc);
string cookie = Request.Cookies["YourCookieName"].Value;
string cookieValue = HttpUtility.UrlDecode( cookie,enc);
System.Text.Encoding enc = System.Text.Encoding.GetEncoding("gb2312");
for (int i = 0; i < HttpContext.Current.Request.Cookies.Count; i++)
{
if (HttpContext.Current.Request.Cookies.Keys[i] == null)
return;
if (HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies.Keys[i]).ToString() == "admin_session_offices")
admin_session_offices = HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies[i].Value.ToString(), enc);
if (HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies.Keys[i]).ToString() == "admin_session_caozuos")
admin_session_caozuos = HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies[i].Value.ToString(), enc);
if (HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies.Keys[i]).ToString() == "admin_session_cishu")
admin_session_cishu = HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies[i].Value.ToString(), enc);
////输出测试
//Response.Write(HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies.Keys[i], enc) + ":" + HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies[i].Value.ToString(), enc) + "<br>");
}
for (int i = 0; i < HttpContext.Current.Request.Cookies.Count; i++)
{
if (HttpContext.Current.Request.Cookies.Keys[i] == null)
return;
if (HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies.Keys[i]).ToString() == "admin_session_offices")
admin_session_offices = HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies[i].Value.ToString(), enc);
if (HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies.Keys[i]).ToString() == "admin_session_caozuos")
admin_session_caozuos = HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies[i].Value.ToString(), enc);
if (HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies.Keys[i]).ToString() == "admin_session_cishu")
admin_session_cishu = HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies[i].Value.ToString(), enc);
////输出测试
//Response.Write(HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies.Keys[i], enc) + ":" + HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies[i].Value.ToString(), enc) + "<br>");
}
//************************** 关于键名乱码的解决方案
<div style="padding-top: 4px; text-align: right; font-weight: normal">
<%=request.Cookies("admin_session_offices")%>
<%=request.Cookies("admin_session_caozuos")%> <br>
累计登陆<%=request.Cookies("admin_session_cishu")%>次 </div>
---------------------------------------------以上是asp的读取。。
aspx:
HttpContext.Current.Request.Cookies["admin_session_caozuos"].Value 报错,而
HttpContext.Current.Request.Cookies["admin%5Fsession%5Fcaozuos"].Value 这样的取值却有效果,
如何统一把cookie里的键及值重新解码??