zoukankan      html  css  js  c++  java
  • ASP.NET乱码解决方案

    应用场景在URL传值和接收中很容易出现乱码,特找到解决方案如下:

    1、在web.config文中<system.web>加入

    <globalization requestEncoding="gb2312" responseEncoding="gb2312" />

    2、对传递的URL进行GB2312编码

    public string InitChineseUrl(string chineseUrl)
            {
                Uri url = new Uri(chineseUrl);
                System.Collections.Specialized.NameValueCollection nv = System.Web.HttpUtility.ParseQueryString(url.Query, System.Text.Encoding.GetEncoding("utf-8"));
                string query = "";
                for (int i = 0; i < nv.Count; i++)
                {
                    if (query.Trim() == string.Empty)
                    {
                        query = "?" + nv.Keys[i] + "=" + HttpUtility.UrlEncode(nv[i], System.Text.Encoding.GetEncoding("GB2312"));
                    }
                    else
                    {
                        query += "&" + nv.Keys[i] + "=" + HttpUtility.UrlEncode(nv[i], System.Text.Encoding.GetEncoding("GB2312"));
                    }
                }
                string u = chineseUrl.Split('?')[0] + query;
                return u;
            }
  • 相关阅读:
    面试汇总
    Windows 环境下的 protoc 安装(转)
    Hbase 元数据一致性检查(转)
    Slow ReadProcessor&amp;Error Slow BlockReceiver错误日志分析(转)
    Hbase CMS GC 调优。
    [技术]排查线上问题
    crontab 误删恢复
    Hbase balancer RSgroup shell 脚本
    Hbase运维手册(1)
    Presto JVM.config
  • 原文地址:https://www.cnblogs.com/yibinboy/p/2245390.html
Copyright © 2011-2022 走看看