<%@ - How to block a website programatically using DotNet

file tags (8)

  1. Create simple http proxy solutions with exclusion list (or look for ready to use solution)
  2. Restrict internet access to access only using Your proxy

I am developing a windows application to block the websites from a computer using DotNet windows programming.I found some results to block an url but not for a website. That is I have to block complete website not a single url.

So can some one help me to solve this problem

Thanking You


Basically you want a proxy server with a black list?

Detect browser URL

you can not access to internet browsers from winform projects but you can access if you have a plug-in app. for browsers. Develop a plug-in app. and communicate with your winform app. like internet download manager app. here is expamle for IE add-ons IE add-on express for chrome Google dev guide

hopefully helps it.

Why are you using an application running on the local machine to do this? It doesn't make much sense. This is done through a corporate proxy, generally.

You may edit the


File to resolve a domain name to '', instead of what it would normally do, to stop it being visible in that fashion. But it's better to do it properly.

Please describe what you're trying to do in more detail.

It sounds like you want the services of the System.Uri class (http://msdn.microsoft.com/en-us/library/system.uri.aspx). I'm guessing that at some point you have to decide whether or not you are going to allow or disallow a request based on the URI, in which case you will want logic similar to the following:

Uri uri = new Uri("http://www.google.co.uk/somepage.html");
if (uri.Host.ToLower().EndsWith("google.co.uk"))
    // Do something

Experiment with something like that. Things to note are that:

  • If you check to see if the host equals "www.google.co.uk" then this would still mean that other subdomains (e.g. "www3.google.co.uk") wouldnt be blocked.
  • If you check to see if the host contains "google.co.uk" then you risk blocking others whose subdomain contains (for stupid reasons) someone elses url, for example "google.co.uk.MyDomain.co.uk" which is still a valid (if stupid) subdomain under the "MyDomain.co.uk" domain.

You're going about it the wrong way. You don't want to intercept at the browser level - I'll use a browser or method you've never heard of to get where I want to go. You need to go deeper. Own the network interface or the operating system's network communication (e.g. the hosts file as people said) and authenticate each connection. Ideally, own it outside of the computer - at the network infrastructure level.

How to block a website programatically using DotNet

Have you considered to solve this via firewall rules instead? That would seem more natural to me... An .NET application seems not to be the appropriate technology to implement a web filter. Just for my own curiousity:

why do you wan't to block sites?


Some versions of the .NET framework do not support Enum.GetValues. Here's a good workaround from Ideas 2.0: Enum.GetValues in Compact Framework:

public List<Enum> GetValues(Enum enumeration)
   List<Enum> enumerations = new List<Enum>();
   foreach (FieldInfo fieldInfo in enumeration.GetType().GetFields(
         BindingFlags.Static | BindingFlags.Public))
   return enumerations;

As with any code that involves reflection, you should take steps to ensure it runs only once and results are cached.