C# Corner Annual Conference 2015
Forum guidelines
How to block a Website using C#
Posted By chaithanya on 09 Oct 2009
 I am developing an C# application(not asp.net) in which I have to get the urls typed by the user in the browser and I have to compare the urls with a set of urls and decide whether to allow or to deny the user to navigate to the website.
I have tried with appending to C:\windows\system32\drivers\etc\hosts file but its not working.So Is there any way I can do this?How to block the sites by getting the urls.Can someone suggest me how to approach to the solution with some sites or code that can help me.

Thank You

Re: How to block a Website using C#
Posted By Trinity on 10 Oct 2009  

you can use the webpermission class or webbrowserpermission class you can use them either declarative way using attribute or imperative way by incorporating them in the code

I will never die, I always reborn again and again. Be the matrix with me. Amen
Re: How to block a Website using C#
Posted By Niradhip Chakraborty on 10 Oct 2009  
Take a look at Routing and Remote Access Service APIs in the Platform SDK. You will have to PInvoke functions to build a firewall of sorts (that filters packets).
You also can check the following code:
String path = @"C:\Windows\System32\drivers\etc\hosts";
StreamWriter sw = new StreamWriter(path, true);
String sitetoblock = "\n google.com";

Niradhip(James Hetfield)
Please remember to click “Do you like this answer” on the post that helps you.
Re: How to block a Website using C#
Posted By chaithanya on 12 Oct 2009  
But I have tried with hosts file but if I block www.google.com,and if I type www.google.co.in it allows me to browser to acess google.I need to block entire google.How can I do this?

Thank You

C# Corner Annual Conference 2015


Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.