当前位置: 移动技术网 > IT编程>开发语言>.net > asp.net中url字符串编码乱码的原因与解决方法

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

2017年12月12日  | 移动技术网IT编程  | 我要评论

佛山人才招聘网,灰原哀同人h,wu2198的新浪博客

先看实例

复制代码 代码如下:

 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出来的编码很正常,都是汉字。

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

复制代码 代码如下:

        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;
}
}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网