zoukankan      html  css  js  c++  java
  • asp.net url址址中中文汉字参数传递乱码解决方法

    中文乱码是网站开发中会常碰到的问题,今天我们来讲一下关于url址址中中文汉字参数传递乱码解决方法,有需要的朋友可以参考下。
    在cs文件里传参的时候用UrlEncode:

    Response.Redirect("B.asp教程x?Name="+Server.UrlEncode(Name));

    接参的时候用UrlDecode:

    Response.Write(Server.UrlDecode(Request.QueryString["Name"]));
    脚本儿里传参的时候用escape:

    location.href = "B.aspx?Name="+escape(Name);

    接参的时候仍然用UrlDecode:

    Response.Write(Server.UrlDecode(Request.QueryString["Name"]));
    总结三点方法

    解决的方法一般有3种:

    1.设置web.config文件

    <system.web>
    ......
    <globalization requestEncoding="gb2312" responseEncoding="gb2312" culture="zh-CN" fileEncoding="gb2312" />
    ......
    </system.web(www.111cn.net)>

    2.传递中文之前,将要传递的中文参数进行编码,在接收时再进行解码。
    >> 进行传递

    string Name = "中文参数";
    Response.Redirect("B.aspx?Name="+Server.UrlEncode(Name)) ;

    >> 进行接收

    string Name = Request.QueryString["Name"];
    Response.Write(Server.UrlDecode(Name)) ;

    3.如果是从 .HTML 文件向 .Aspx 文件进行传递中文参数的话(即不从后台用 Redirect()方法进行 Url 转换)。一样要将传递的中文参数进行编码,在接收时再进行解码。
    >> 进行传递

    <script language="JavaScript">
    function GoUrl()
    {
    var Name = "中文参数";
    location.href = "B.aspx?Name="+escape(Name) ;
    }
    <body onclick="GoUrl()">

    >> 进行接收

    string Name = Request.QueryString["Name"];
    Response.Write(Server.UrlDecode(Name))
    from:http://www.111cn.net/net/160/38841.htm

  • 相关阅读:
    换行符 CR
    c# 定义的属性名与保留关键字冲突
    Redis 以window 服务启动
    c# Guid.NewGuid().ToString(format
    select 下拉源动态赋值
    html 控制input标签只能输入数字
    HTTP 错误 500.19
    Android debugger 出现提示Connected to the target VM, address: 'localhost:xxxx', transport: 'socket'
    siege--Web性能压测工具
    python+selenium上传文件注意点
  • 原文地址:https://www.cnblogs.com/alibai/p/4023203.html
Copyright © 2011-2022 走看看