| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1295 人关注过本帖
标题:【求助】在地址栏输入汉字后在后台获取显示乱码!
只看楼主 加入收藏
bshao0001
Rank: 1
来 自:青岛
等 级:新手上路
帖 子:3
专家分:0
注 册:2009-11-12
结帖率:50%
收藏
已结贴  问题点数:5 回复次数:2 
【求助】在地址栏输入汉字后在后台获取显示乱码!
图片附件: 游客没有浏览图片的权限,请 登录注册

程序代码:
  Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
                Request.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
                searchvalue = NewRay.utils.RequestClass.GetQueryString("searchvalue").Trim();
                searchvalue = HttpUtility.UrlDecode(searchvalue, System.Text.Encoding.UTF8);
搜索更多相关主题的帖子: 后台 获取 地址 乱码 汉字 
2009-11-12 11:55
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:5 
UrlEncode

飘过~~
2009-11-12 12:24
bshao0001
Rank: 1
来 自:青岛
等 级:新手上路
帖 子:3
专家分:0
注 册:2009-11-12
收藏
得分:0 
不过我想了一个解决办法:
1.创建一个HttpModule 类在此类中进行Url重写:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;
namespace NewRay.Web.HttpModule
{
    public class DecodeModule:IHttpModule
    {
        #region IHttpModule 成员

        public void Dispose()
        {
            throw new NotImplementedException();
        }

        public void Init(HttpApplication context)
        {
            context.BeginRequest += new EventHandler(context_BeginRequest);
        }

        void context_BeginRequest(object sender, EventArgs e)
        {
            HttpApplication application = (HttpApplication)sender;
            HttpContext context = application.Context;
            string str = context.Request.RawUrl;
            int eqindex = str.LastIndexOf('=');
            int sv = str.IndexOf("searchvalue");
            if (eqindex > 0 && sv > 0)
            {
                string nowstr = str.Substring(eqindex + 1);
                if (!"".Equals(nowstr) && nowstr != null)
                {
                    Regex reg = new Regex("^[\u4e00-\u9fa5]{0,}$");

                    if (reg.IsMatch(nowstr))
                    {

                        string schineser = HttpUtility.UrlEncode(nowstr);

                        context.RewritePath("/searchlist.aspx?typevalue=product&pctype=tese&searchvalue=" + schineser + "");
                    }
                }
            }
        }

        #endregion
    }
}
2.在后台进行解码:
string str= HttpUtility.UrlDecode(strvalue);
注:在ie内核的好用。

21世纪,什么最重要——我!
2009-11-14 09:10
快速回复:【求助】在地址栏输入汉字后在后台获取显示乱码!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017470 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved