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

首頁 > 編程 > .NET > 正文

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

2024-07-10 12:43:50
字體:
來源:轉載
供稿:網友

對于大中型網站,為了增強用戶體驗,往往需要根據不同城市站點的用戶推送或展現相應個性化的內容,如對于一些大型門戶網站的新聞會有城市站點的功能,如果沒有設置相應的城市站點,默認就是根據用戶訪問的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();

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 手游| 南部县| 原平市| 沈丘县| 泰顺县| 唐山市| 泽普县| 五常市| 百色市| 五莲县| 慈利县| 抚远县| 平潭县| 新丰县| 洛隆县| 凤山县| 遂川县| 盐津县| 珲春市| 台南县| 合川市| 合肥市| 咸阳市| 邵武市| 水富县| 安顺市| 双江| 辛集市| 天气| 潢川县| 孙吴县| 旬阳县| 什邡市| 惠来县| 镇平县| 马关县| 绥江县| 扶绥县| 民县| 扶绥县| 衡南县|