网站编码格式是utf-8 <globalization responseEncoding="utf-8" requestEncoding="utf-8"/>
如果我在IE7里面直接输入http://localhost/List.aspx?name=我们 (不对name参数值进行编码)
这样带中文参数的网址.用Request["name"] 或Request.QueryString["zixunName"]等等.都取不到正确的值
. 我不想改变网站的编码格式.
如果我在IE7里面直接输入http://localhost/List.aspx?name=我们 (不对name参数值进行编码)
这样带中文参数的网址.用Request["name"] 或Request.QueryString["zixunName"]等等.都取不到正确的值
. 我不想改变网站的编码格式.
解决方案 »
- gridview
- 当数据库里面有一条数据写入的时候,页面有一个提示,提示有一条新的数据更新。
- C#截取视频的第一个画面保存为图片
- 简单工厂和抽象工厂的区别
- data中加一个“序号”的列怎么加?
- datalist的问题
- 这是我的 repeater 分页的代码,但是运行起来总是报错.请高手帮忙解决
- vs2005 treeview 控件节点单击事件,如何只调用 js 代码?
- vs2005将com或.framewok控件加入工具箱
- Gridview后台如何调数据库啊
- 关于GridView使用存储过程的问题
- ----------------怎样在GridView的commandfield中添加客户端事件?
Uri.UnescapeDataString(Request["name"])
你想要取原始的未编码的东西就得把Request.RawUrl自己拿去分离出参数名及值,因为RawUrl是没有被解码的原始内容
Request[] 里的东西都是解码了的,如果客户端提交的编码和服务器的解码不匹配,那里面的值就是乱码
{
if (!Uri.IsWellFormedUriString(Request.RawUrl, UriKind.Absolute))
{
rawurl = Uri.UnescapeDataString(Request.RawUrl);
} if (rawurl.Contains("?"))
{
string[] ss = rawurl.Split(new char[] { '?' }, StringSplitOptions.RemoveEmptyEntries);
if (ss.Length > 0)
{
NameValueCollection nvc = HttpUtility.ParseQueryString(ss[1]);
return nvc;
}
} return null;
} protected void Page_Load(object sender, EventArgs e)
{ NameValueCollection qs = QueryStringEx(Request.RawUrl);
Response.Write(qs["q"]);
}http://xxx/?q=%E6%88%91%E7%88%B1%E4%B8%AD%E5%9B%BD
http://xxx/?q=我爱中国
看看效果如何
反正思路就是先检查Url有无被转义,有的话先转正,没有的就直接分离生成命名集供使用
感谢你这么有诚意的帮我解决问题.你的方法我都试了,还是没能解决问题,主要问题是Request.RawUrl的值的参数部分是���� 这样的乱码,而不是被转义过的.
这个方法可行?
能加下你QQ吗?我QQ286557139
dim a as string=server.urlencode(request("name"))
//string utfinfo = txtKeyword.Text;
//string gb2312info = string.Empty; //System.Text.Encoding utf8 = System.Text.Encoding.UTF8;
//System.Text.Encoding gb2312 = System.Text.Encoding.GetEncoding("gb2312"); //// Convert the string into a byte[].
//byte[] unicodeBytes = utf8.GetBytes(utfinfo);
//// Perform the conversion from one encoding to the other.
//byte[] asciiBytes = System.Text.Encoding.Convert(utf8, gb2312, unicodeBytes); //// Convert the new byte[] into a char[] and then into a string.
//// This is a slightly different approach to converting to illustrate
//// the use of GetCharCount/GetChars.
//char[] asciiChars = new char[gb2312.GetCharCount(asciiBytes, 0, asciiBytes.Length)];
//gb2312.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);
//gb2312info = new string(asciiChars);
这是一段 编码转换的代码 你把 Request["name"] 的值 转换一下编码