天天看點

Asp.net url傳遞中文的解決方案

1.設定web.config檔案。

<system.web>

......

<globalization requestencoding="gb2312" responseencoding="gb2312" culture="zh-cn" fileencoding="gb2312" />

</system.web>

2.傳遞中文之前,将要傳遞的中文參數進行編碼,在接收時再進行解碼。

>> 進行傳遞

string name = "中文參數";

response.redirect("b.aspx?name="+server.urlencode或httputility.urlencodeunicode (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);

}

</script>

<body onclick="gourl()">

一般來說。設定web.config檔案就可以了。但是如果你用 javascript 調用 webservice 方法的話(往webservice裡面傳遞中文參數)。設定 web.config 檔案好象無效。

4、html檔案向aspx頁面傳遞中文參數

    >> 進行傳遞

     <script language="javascript">

     function gourl()

     {

          var name = "中文參數";

          location.href

                =onlinesend.aspx?name =" + encodeuri(name)+ "&sid="  + math.random().tostring();

          //在請求某個頁面并傳遞參數時,請在後面再加個傳遞參數(值為随機數) ,以儲存下次請求時ie

          //浏覽器認為不是請求的同一個頁面,否則ie浏覽器認為是請求的統一頁面,會從緩存中打開該頁

          //面,導緻參數不能正确傳遞過去    sid=" + math.random().tostring();

     }

     </script>

    <body onclick="gourl()">

   >> 進行接收

    string name =request.querystring["name "].tostring();

    原帖位址:http://greatverve.cnblogs.com/archive/2011/06/25/url-character.html

繼續閱讀