问题描述
请问在asp.net(aspx)页面使用Qstring方式传“汉字”参给asp页面出现乱码怎么解决?aspx页面使用了以下三几种编码://stringstrXianMing=System.Web.HttpUtility.UrlEncode(ddlXianMing.SelectedValue,Encoding.GetEncoding("GB2312"));//stringstrXingBie=System.Web.HttpUtility.UrlEncode(ddlXingBie.SelectedValue,Encoding.GetEncoding("GB2312"));//stringstrXianMing=System.Web.HttpUtility.UrlEncode(ddlXianMing.SelectedValue,Encoding.GetEncoding("UTF-8"));//stringstrXingBie=System.Web.HttpUtility.UrlEncode(ddlXingBie.SelectedValue,Encoding.GetEncoding("UTF-8"));stringstrXianMing=System.Web.HttpUtility.HtmlEncode(ddlXianMing.SelectedValue);stringstrXingBie=System.Web.HttpUtility.HtmlEncode(ddlXingBie.SelectedValue);
asp页面接收参数部分如下:FunctionUrlDecode_GBToUtf8(ByValstr)DimB,ub''中文字的Unicode码(2字节)DimUtfB''Utf-8单个字节DimUtfB1,UtfB2,UtfB3''Utf-8码的三个字节Dimi,n,sn=0ub=0Fori=1ToLen(str)B=Mid(str,i,1)SelectCaseBCase"+"s=s&""Case"%"ub=Mid(str,i+1,2)UtfB=CInt("&H"&ub)IfUtfB<128Theni=i+2s=s&ChrW(UtfB)ElseUtfB1=(UtfBAnd&H0F)*&H1000''取第1个Utf-8字节的二进制后4位UtfB2=(CInt("&H"&Mid(str,i+4,2))And&H3F)*&H40''取第2个Utf-8字节的二进制后6位UtfB3=CInt("&H"&Mid(str,i+7,2))And&H3F''取第3个Utf-8字节的二进制后6位s=s&ChrW(UtfB1OrUtfB2OrUtfB3)i=i+8EndIfCaseElse''Ascii码s=s&BEndSelectNextUrlDecode_GBToUtf8=sEndFunctionFunctionURLDecode(enStr)dimdeStr,strSpecialdimc,i,vdeStr=""strSpecial="!""#$%&'()*+,.-_/:;<=>?@[]^`{|}~%"fori=1tolen(enStr)c=Mid(enStr,i,1)ifc="%"thenv=eval("&h"+Mid(enStr,i+1,2))ifinStr(strSpecial,chr(v))>0thendeStr=deStr&chr(v)i=i+2elsev=eval("&h"+Mid(enStr,i+1,2)+Mid(enStr,i+4,2))deStr=deStr&chr(v)i=i+5endifelseifc="+"thendeStr=deStr&""elsedeStr=deStr&cendifendifnextURLDecode=deStrEndfunctionresponse.WriteUrlDecode_GBToUtf8(request("xianming"))&""&UrlDecode_GBToUtf8(request("xingbie"))&""&request("minlicheng")&""&request("maxlicheng")&"</br>"response.WriteURLDecode(request("xianming"))&""&URLDecode(request("xingbie"))&""&request("minlicheng")&""&request("maxlicheng")&"</br>"response.Writerequest("xianming")&""&request("xingbie")&""&request("minlicheng")&""&request("maxlicheng")response.End
求教这个怎么破牙!
解决方案
解决方案二:
用js算了。。。这个有点烦,之前用过
解决方案三:
HttpUtility.UrlEncode有一个对应的UrlDeCode的~不用自己写
解决方案四:
引用2楼moonwrite的回复:
HttpUtility.UrlEncode有一个对应的UrlDeCode的~不用自己写
asp有类似于UrlDeCode的语句吗?
解决方案五:
config设置一下编码,统一一下编码,asp的编码和aspx一直,你试试web.config<system.web><globalizationresponseEncoding="gb2312"requestEncoding="gb2312"fileEncoding="gb2312"/>或者<globalizationresponseEncoding="utf-8"requestEncoding="utf-8"fileEncoding="utf-8"/><system.web>
解决方案六:
1:web.config<system.web><globalizationresponseEncoding="gb2312"requestEncoding="gb2312"fileEncoding="gb2312"/><system.web>asp页面设置<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">2:可以尝试用session传递