asp.net中url字符串编码乱码的原因与解决方法

(编辑:jimmy 日期: 2024/10/6 浏览:2)

先看实例
复制代码 代码如下:
 function webChart() {
            var t = document.getElementById("txtReceive");
            if (t.value == null || t.value == "") {
                alert("请先进行查询");
            }
            else {

                alert(t.value);
                document.getElementById("center-iframe").src = "map/industryMap.aspx?_indeustry=" + t.value;
}}



这个时候alert出来的编码很正常,都是汉字。

asp.net中url字符串编码乱码的原因与解决方法

但是在后台获取时已经乱码

复制代码 代码如下:
        protected void Page_Load(object sender, EventArgs e)
        {
            Industry = Request.QueryString["_indeustry"].ToString();

            InitMap();
            getShowMuilt();
        }

web.config已经配置为UTF-8 但是还是不行
复制代码 代码如下:
<system.web>
    <globalization culture="en-US" uiCulture="en" requestEncoding="UTF-8"
                   responseEncoding="UTF-8" fileEncoding="UTF-8" />
  </system.web>



最终解决方案

复制代码 代码如下:
 function webChart() {
            var t = document.getElementById("txtReceive");
            if (t.value == null || t.value == "") {
                alert("请先进行查询");
            }
            else {
                var url = encodeURI("map/industryMap.aspx?_indeustry=" + t.value);
                alert(url);
                document.getElementById("center-iframe").src = url;
}
}

asp.net中url字符串编码乱码的原因与解决方法

一句话新闻
Windows上运行安卓你用过了吗
在去年的5月23日,借助Intel Bridge Technology以及Intel Celadon两项技术的驱动,Intel为PC用户带来了Android On Windows(AOW)平台,并携手国内软件公司腾讯共同推出了腾讯应用宝电脑版,将Windows与安卓两大生态进行了融合,PC的使用体验随即被带入到了一个全新的阶段。