|
<globalization requestEncoding="gb2312" responseEncoding="gb2312"/>
頁(yè)面Header部分也都有
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
真是奇怪,
只好用了笨辦法:
寫(xiě)參數(shù):
復(fù)制代碼 代碼如下:
string strurl = PreUrl + "?word={0}&sort={1}&check={2}";
strurl = string.Format(strurl, HttpUtility.UrlEncode(this.txtSearchTxt.Text.Trim(), System.Text.Encoding.GetEncoding("GB2312")), this.radiosortDesc.SelectedIndex.ToString(), CheckState.ToString());
Page.Response.Redirect(strurl);
//注意編碼方式為gb2312
讀參數(shù):
復(fù)制代碼 代碼如下:
try
{ if (Page.Request.QueryString["word"] != null)
{ _word = Convert.ToString(HttpUtility.UrlDecode(Page.Request.QueryString["word"], System.Text.Encoding.GetEncoding("GB2312"))); }
}
catch { _word = String.Empty; }
///注意編碼方式為gb2312,與前面對(duì)應(yīng)
后來(lái),看了孟子的文章,才發(fā)現(xiàn)有更好的解決方案:
用Javascript!
寫(xiě)一個(gè)方法放在基類頁(yè)面中
復(fù)制代碼 代碼如下:
public void PageLocation(string chineseURL)
{
if(chineseURL==null || chineseURL.Trim().Length==0 )
{return;//還可能不是一個(gè)合法的URL Tony 2007/11/15
}
Page.ClientScript.RegisterStartupScript(this.GetType(), "AgroNETPageLocationTo", "<script type='text/Javascript' language='Javascript'> window.location.href='"+chineseURL+"';</script>");
}
然后在頁(yè)面中調(diào)用
復(fù)制代碼 代碼如下:
string strurl = PreUrl + "?word={0}&sort={1}&check={2}";
strurl = string.Format(strurl, this.txtSearchTxt.Text.Trim(), this.radiosortDesc.SelectedIndex.ToString(), CheckState.ToString());
PageLocation(strurl);
注意后種方法用了Javasrcipt,實(shí)際應(yīng)用在分頁(yè)時(shí)需要保持中文參數(shù),最好還是用window.Location.Href方法!
最后,如果一要在Javascript與.NET后臺(tái)代碼進(jìn)行對(duì)話,可以這樣:
復(fù)制代碼 代碼如下:
<script language= "JavaScript " >
function GoUrl()
{
var Name = "中文參數(shù) ";
location.href = "B.ASPx?Name= "+escape(Name);
}
</script >
<body onclick= "GoUrl() " >
接收:
復(fù)制代碼 代碼如下:
string Name = Request.QueryString[ "Name "];
Response.Write(HttpUtility.UrlDecode(Name));
要點(diǎn)是:
將傳遞的中文參數(shù)進(jìn)行編碼,在接收時(shí)再進(jìn)行解碼。
完。
AspNet技術(shù):asp.net中url地址傳送中文參數(shù)時(shí)的兩種解決方案,轉(zhuǎn)載需保留來(lái)源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。