using System;
using System.Collections.Generic;
using System.Web;
namespace DomainModel.Services
{
public class BlockIPModule : IHttpModule
{
public void Dispose() { }
private List<string> badIPs = new List<string> { "213.5.70.205", "188.92.75.82" };
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(Application_BeginRequest);
}
private void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext context = ((HttpApplication)sender).Context;
string currentIP = context.Request.UserHostAddress;
if (!IsIpValid(currentIP))
{
context.Response.StatusCode = 403;
}
}
private bool IsIpValid(string checkIP)
{
var isValid = !(badIPs.Contains(checkIP));
return (isValid);
}
}
}
Bookmarks