国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > 建站經驗 > 正文

asp.net網站首頁根據IP自動跳轉指定頁面的示例

2019-11-02 15:53:44
字體:
來源:轉載
供稿:網友

 本文介紹的程序主要實現根據IP地址或地址段或IP所在城市進行自動跳轉到指定頁面的功能,需要的朋友可以參考下

對于大中型網站,為了增強用戶體驗,往往需要根據不同城市站點的用戶推送或展現相應個性化的內容,如對于一些大型門戶網站的新聞會有城市站點的功能,如果沒有設置相應的城市站點,默認就是根據用戶訪問的IP地址的所在城市自動設置。本文主要通過自定義擴展IHttpModule接口,考慮到性能IP數據庫主要采用QQwry純真IP數據庫,主要實現根據IP地址或地址段或IP所在城市進行自動跳轉到指定頁面的功能(支持Nginx作為前端反向代理服務器),該WebsiteSkip組件核心代碼如下: 代碼如下:using System;using System.Collections.Generic;using System.Text;using System.Web;using System.Xml;using System.IO;using System.Net;using System.Text.RegularExpressions;using NetOpen_System.Component.QQWry; namespace NetOpen_System.Component{    public sealed class WebsiteSkipHttpModule : IHttpModule    {        #region IHttpModule 成員         public void Dispose()        {        }         public void Init(HttpApplication context)        {            context.BeginRequest += new EventHandler(context_BeginRequest);        }          #endregion          void context_BeginRequest(object sender, EventArgs e)        {            try            {                 //if (HttpContext.Current.Request.IsLocal)//忽略本地計算機請求                //    return;                 //string ip = HttpContext.Current.Request.UserHostAddress;                //string ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();                string ip = string.Empty;                if (HttpContext.Current.Request.ServerVariables["HTTP_X_REAL_IP"] != null)                {                    ip = HttpContext.Current.Request.ServerVariables["HTTP_X_REAL_IP"].ToString();                }                else if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)                {                    ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();                }                else if (HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)                {                    ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();                }                else                {                    ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();                }                  QQWryLocator qqWry = new QQWryLocator(HttpContext.Current.Server.MapPath(@"~IpDataqqwry.dat"));                 IPLocation ipaddress = qqWry.Query(ip);  //查詢一個IP地址                 string ls_city = ipaddress.Country;                string ls_urlfrom = string.Empty;                string ls_urlto = string.Empty;                string ls_url = HttpContext.Current.Request.Url.AbsoluteUri;                string ls_useragentkeyword = string.Empty;                 ExcludeUserAgentMatchEngine Em = WebsiteSkipConfiguration.GetConfig().ExcludeUserAgents;                 if(Em.ExcludeUserAgentList.Count > 0)                {                    foreach (ExcludeUserAgent ua in Em.ExcludeUserAgentList)                    {                        if (HttpContext.Current.Request.UserAgent.Contains(ua.keyword))                        {                            return;                        }                    }                }                 UrlMatchEngine pu = WebsiteSkipConfiguration.GetConfig().SkipedUrls;                 if (pu.UrlList.Count > 0)                {                    foreach (SkipedUrl sk in pu.UrlList)                    {                         if (ls_city.Contains(sk.IpCity))                        {                            if (sk.UrlFrom.Length > 0)                            {                                if (sk.UrlFrom.Contains(ls_url) && !ls_url.Contains(sk.OutKey
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 镇康县| 临沭县| 石嘴山市| 阜康市| 资兴市| 德兴市| 永修县| 中方县| 方城县| 兰考县| 赤壁市| 灵山县| 济源市| 交口县| 新和县| 枣庄市| 鄂伦春自治旗| 北宁市| 沿河| 和田县| 牙克石市| 大厂| 宿迁市| 惠东县| 黔江区| 宜君县| 闻喜县| 六安市| 黑水县| 丹棱县| 资阳市| 通海县| 渭源县| 新营市| 临汾市| 增城市| 泰宁县| 海淀区| 进贤县| 金阳县| 巴林左旗|