日期:2014-05-20 浏览次数:20935 次
/// <summary>
/// 名 称:<br>
/// </summary>
/// <remarks>
/// 版 本:1.0<br>
/// 作 者:****<br>
/// 创始时间:2011-5-20 17:00:02<br>
/// 描 述:
/// ----------修改记录------------<br>
/// </remarks>
public class WarningHttpModule : IHttpModule, IRequiresSessionState
{
protected static readonly ILog log = LogManager.GetLogger("*******");
protected static Thread thread = null;
protected static IVisitAnalysisHandle analysisHander = null;
protected static VisitManager visitManager = VisitManager.GetInstance();
private static object LockHelper = new object();
static WarningHttpModule()
{
if (null == thread)
{
lock (LockHelper)
{
if (null == thread)
{
thread = new Thread(new ThreadStart(Process));
thread.Start();
}
}
}
if (null == analysisHander)
{
lock (LockHelper)
{
if (null == analysisHander)
{
try
{
analysisHander = (IVisitAnalysisHandle)Activator.GetObject(typeof(IVisitAnalysisHandle), "tcp://127.0.0.1:6666/GNT");
}
catch (Exception ex)
{
throw new Exception("注册预警系统信道失败", ex); ;
}
}
}
}
}
private void Application_BeginRequest(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
HttpContext context = application.Context;
HttpRequest request = application.Request;
HttpResponse response = application.Response;
string url = request.RawUrl.ToLower(); //获取当前原始请求的url
string ip = request.UserHostAddress;
string extension = System.IO.Path.GetExtension(url).ToLower();
//是需要检测的页面
if (extension != ".aspx" && extension != ".asmx" && extension != ".ashx")
{ return; }
//在白名单范围内
if (visitManager.IsInWhiteListIP(ip))
{ return; }
//添加到访问记录里面
visitManager.AddRequest(DateTime.Now, ip, url);
//如果是异常ip的请求页
if (url == "/visitwarning.aspx")