⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myhttpmodule.cs

📁 IP锁定程序实例源码 ip focus program example recourse code
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
//该源码下载自www.51aspx.com(51aspx.com)

namespace BlockIP
{
    public class MyHttpModule : IHttpModule
    {
        public void Init(HttpApplication app)
        {
            //接收请求开始处理
            app.BeginRequest += new EventHandler(app_BeginRequest);
        }

        void app_BeginRequest(object sender, EventArgs e)
        {
            Hashtable hash = (Hashtable)HttpContext.Current.Application["blockip"];
            if (hash != null && hash.Contains(HttpContext.Current.Request.UserHostAddress))
            {
                HttpContext.Current.Response.Write("来源IP["+HttpContext.Current.Request.UserHostAddress.ToString()+"]不在允许访问之内<br><br>请与管理员联系解决!");//输出提示信息。
                HttpContext.Current.Response.End();//终止请求。
            }
            else
            { 
                HttpContext.Current.Response.Write("恭喜,你的IP不在受限访问51aspx之列!");//输出提示信息。
            
            }
        }

        public void Dispose() { }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -