电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

Request.Referer的乱码终极解决方法+获得用户是用什么关键字通过搜索引擎进来的VIP免费

Request.Referer的乱码终极解决方法+获得用户是用什么关键字通过搜索引擎进来的_第1页
Request.Referer的乱码终极解决方法+获得用户是用什么关键字通过搜索引擎进来的_第2页
Request.Referer的乱码终极解决方法+获得用户是用什么关键字通过搜索引擎进来的_第3页
Request.Referer的乱码终极解决方法+获得用户是用什么关键字通过搜索引擎进来的分类:ASP.NET2009-12-1018:08255人阅读评论(0)收藏举报当你想获取Url字符串的时候,最好不要直接调用Request.UrlReferrer.ToString()方法,因为这样有可能返回的是一堆乱码。产生的原因是,用户在来你网站之前的那个网站的编码方式(Encoding)也许和你的网站不一样,导致UrlDecode的时候出现了乱码。这里建议使用Request.UrlReferrer.OriginalString,这个属性返回的就是当时构造Uri对象的原始Url。以下为获得用户是用什么关键字通过搜索引擎进来的方法viewplaincopytoclipboardprint?1.stringRegx="";2.stringRefUrl=Request.UrlReferrer.OriginalString;3.//Response.Write(HttpUtility.UrlDecode(RefUrl,System.Text.Encoding.GetEncoding("gb2312")));4.if(RefUrl.ToLower().Contains("google"))5.{6.RefUrl=HttpUtility.UrlDecode(RefUrl,System.Text.Encoding.GetEncoding("utf-8"));7.Regx="&q=(?[//w*%+]*).*";8.}9.if(RefUrl.Contains("baidu.com"))10.{11.RefUrl=HttpUtility.UrlDecode(RefUrl,System.Text.Encoding.GetEncoding("gb2312"));12.Regx="wd=(?[//w*%+]*).*";13.}14.if(RefUrl.Contains("soso.com"))15.{16.RefUrl=HttpUtility.UrlDecode(RefUrl,System.Text.Encoding.GetEncoding("gb2312"));17.Regx="w=(?[//w*%+]*).*";18.}19.if(RefUrl.Contains("sogou.com"))20.{21.RefUrl=HttpUtility.UrlDecode(RefUrl,System.Text.Encoding.GetEncoding("gb2312"));22.Regx="query=(?[//w*%+]*).*";23.}24.if(RefUrl.Contains("yahoo.com"))25.{26.RefUrl=HttpUtility.UrlDecode(RefUrl,System.Text.Encoding.GetEncoding("utf-8"));27.Regx="p=(?[//w*%+]*).*";28.}29.if(RefUrl.Contains("bing.com"))30.{31.RefUrl=HttpUtility.UrlDecode(RefUrl,System.Text.Encoding.GetEncoding("utf-8"));32.Regx="q=(?[//w*%+]*).*";33.}34.if(Regx=="")35.{36.ForSearcherDiv.Visible=false;37.return;38.}39.Regexr=newRegex(Regx);//定义一个Regex对象实例40.Matchm=r.Match(RefUrl);//在字符串中匹配41.42.//Response.Write("
"+Regx);43.//Response.Write("
"+m.Success.ToString());44.if(m.Success)45.{46.47.SearchKey=m.Groups["key"].Value;48.49.}50.[c-sharp]viewplaincopy1.stringRegx="";2.stringRefUrl=Request.UrlReferrer.OriginalString;3.//Response.Write(HttpUtility.UrlDecode(RefUrl,System.Text.Encoding.GetEncoding("gb2312")));4.if(RefUrl.ToLower().Contains("google"))5.{6.RefUrl=HttpUtility.UrlDecode(RefUrl,System.Text.Encoding.GetEncoding("utf-8"));7.Regx="&q=(?[//w*%+]*).*";8.}9.if(RefUrl.Contains("baidu.com"))10.{11.RefUrl=HttpUtility.UrlDecode(RefUrl,System.Text.Encoding.GetEncoding("gb2312"));12.Regx="wd=(?[//w*%+]*).*";13.}14.if(RefUrl.Contains("soso.com"))15.{16.RefUrl=HttpUtility.UrlDecode(RefUrl,System.Text.Encoding.GetEncoding("gb2312"));17.Regx="w=(?[//w*%+]*).*";18.}19.if(RefUrl.Contains("sogou.com"))20.{21.RefUrl=HttpUtility.UrlDecode(RefUrl,System.Text.Encoding.GetEncoding("gb2312"));22.Regx="query=(?[//w*%+]*).*";23.}24.if(RefUrl.Contains("yahoo.com"))25.{26.RefUrl=HttpUtility.UrlDecode(RefUrl,System.Text.Encoding.GetEncoding("utf-8"));27.Regx="p=(?[//w*%+]*).*";28.}29.if(RefUrl.Contains("bing.com"))30.{31.RefUrl=HttpUtility.UrlDecode(RefUrl,System.Text.Encoding.GetEncoding("utf-8"));32.Regx="q=(?[//w*%+]*).*";33.}34.if(Regx=="")35.{36.ForSearcherDiv.Visible=false;37.return;38.}39.Regexr=newRegex(Regx);//定义一个Regex对象实例40.Matchm=r.Match(RefUrl);//在字符串中匹配41.42.//Response.Write("
"+Regx);43.//Response.Write("
"+m.Success.ToString());44.if(m.Success)4...

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

墨香书阁+ 关注
实名认证
内容提供者

热爱教学事业,对互联网知识分享很感兴趣

确认删除?
VIP
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群
客服邮箱
回到顶部