// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Generic; using System.Web; public class BlockerModule : IHttpModule { private Dictionary banlist; public void Init(HttpApplication app) { banlist = new Dictionary(); // læs banlist fra fil eller database - her tildeler vi bare et par værdier banlist.Add("192.168.0.10", "Ingen adgang"); banlist.Add("192.168.0.11", "Forsvind"); app.BeginRequest += OnBeginRequest; } protected void OnBeginRequest(object sender, EventArgs e) { HttpApplication app = (HttpApplication)sender; string ip = app.Context.Request.UserHostAddress; if(banlist.ContainsKey(ip)) { app.Context.Response.StatusCode = 403; app.Context.Response.StatusDescription = banlist[ip]; app.Context.Response.SuppressContent = true; app.Context.Response.End(); } } public void Dispose() { } }