Forum guidelines
How to block a Website using C#
Posted on: 09 Oct 2009
 I am developing an C# application(not 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 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 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";

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 on: 12 Oct 2009  
But I have tried with hosts file but if I block,and if I type it allows me to browser to acess google.I need to block entire google.How can I do this?

Thank You


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.