Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
localhostBlocker
using System;
using System.Web;
using System.Text.RegularExpressions;
namespace localhostBlocker
{
/// <summary>
/// localhost access blocker
/// </summary>
public class Blocker : IHttpModule
{
public void Init(HttpApplication context)
{
context.PreRequestHandlerExecute += new EventHandler(OnPreRequestHandlerExecute);
}
private void OnPreRequestHandlerExecute(object sender, EventArgs e)
{
string hostName = HttpContext.Current.Request.Url.Host;
if (!String.IsNullOrEmpty(hostName))
{
try
{
Regex regx = new Regex(@"^localhost$");
if (regx.IsMatch(hostName))
{
HttpContext.Current.Response.Close();
}
}
catch (Exception)
{
throw;
}
}
}
public void Dispose()
{
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.