首页 > 代码库 > 跨页面传值之Cookie 中文乱码问题

跨页面传值之Cookie 中文乱码问题

写入Cookie  

  protected void Button1_Click(object sender, EventArgs e)
    {
        HttpCookie _ck = new HttpCookie("persion");
        _ck.Value = http://www.mamicode.com/HttpUtility.UrlEncode( "小杨");
        _ck.Expires = DateTime.Now.AddDays(1);
        Response.Cookies.Add(_ck);

    }

  

读取Cookie

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Cookies["persion"] != null)
        {
            string _s;
            _s =  Request.Cookies["persion"].Value;
            Response.Write(HttpUtility.UrlDecode(_s));
        }
    }

 

红色标记不添加会导致读取Cookie“中文”乱码。

跨页面传值之Cookie 中文乱码问题