温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:IP锁定程序实例源码
当前文件:
BlockIP/MyHttpModule.cs[1K,2009-6-12 11:33:54],打开代码结构图
BlockIP/MyHttpModule.cs[1K,2009-6-12 11:33:54],打开代码结构图1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Web; 5
using System.Web.Security; 6
using System.Web.UI; 7
using System.Web.UI.WebControls; 8
using System.Web.UI.WebControls.WebParts; 9
using System.Web.UI.HtmlControls; 10
using System.Collections; 11
//该源码下载自www.51aspx.com(51aspx.com) 12
13
namespace BlockIP 14
{ 15
public class MyHttpModule : IHttpModule 16
{ 17
public void Init(HttpApplication app) 18
{ 19
//接收请求开始处理 20
app.BeginRequest += new EventHandler(app_BeginRequest); 21
} 22
23
void app_BeginRequest(object sender, EventArgs e) 24
{ 25
Hashtable hash = (Hashtable)HttpContext.Current.Application["blockip"]; 26
if (hash != null && hash.Contains(HttpContext.Current.Request.UserHostAddress)) 27
{ 28
HttpContext.Current.Response.Write("来源IP["+HttpContext.Current.Request.UserHostAddress.ToString()+"]不在允许访问之内<br><br>请与管理员联系解决!");//输出提示信息。 29
HttpContext.Current.Response.End();//终止请求。 30
} 31
else 32
{ 33
HttpContext.Current.Response.Write("恭喜,你的IP不在受限访问51aspx之列!");//输出提示信息。 34
35
} 36
} 37
38
public void Dispose() { } 39
} 40
} 41






}
}