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;
            }
  • 相关阅读:
    CenterNet-TensorRT错误记录
    NAS研究要点分析
    conda如何安装从源下载的离线安装包
    Xavier上pytorch半精度inference问题
    Xavier 使用便携程序
    Xavier疑问
    Python输入(Leetcode
    兴趣爱好
    生活目标
    TX2装机教程
  • 原文地址:https://www.cnblogs.com/yibinboy/p/2245390.html
Copyright © 2011-2022 走看看