How to block Ip ranges using http modules with c# . I have a simple solution but its for single Ip and How can I read IPs from xml file in http modules so that if an IP is there in that file it will be blocked .Here is my code
public class MyHandler :IHttpModule
{
public MyHandler(){}
public bool IsReusable
{
get { return false; }
}
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(Application_BeginRequest);
}
private void Application_BeginRequest(object source, EventArgs e)
{
HttpContext context = (source as HttpApplication).Context;
List<string> BlackListIp = new List<string>();
BlackListIp.Add("127.0.0.1");
if (BlackListIp.Contains(context.Request.UserHostAddress))
{
context.Response.Write("<h1 style='color:red;'>Your IP is Blocked</h1>");
}
}
public void Dispose()
{
}
}