Click here to Skip to main content
15,905,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
private void btnBlock_Click(object sender, EventArgs e)
{
            String path = @"C:\Windows\System32\drivers\etc\hosts";
            StreamWriter sw = new StreamWriter(path, true);
            String sitetoblock = "\n 127.0.0.0 www.facebook.com";
            sw.Write(sitetoblock);
            sw.Close();
            MessageBox.Show("Site Blocked");
}


I used this code. but its not working properly. Please suggest me to improve this code and if there is any other way to do this so please tell me.
Posted
Updated 9-Feb-15 17:46pm
v2
Comments
DamithSL 9-Feb-15 23:59pm    
Asp.net code behind excute on server and it can't change/ovewrite client machine files.
even if you try using client side scripting language, users can disable running scripts using browser settings.
You better try to control web access using your router configuration.
Herman<T>.Instance 10-Feb-15 3:32am    
What is not working properly. Any Exception?
Brinda Lakhani 10-Feb-15 22:30pm    
It blocks only some sites because many sites has multiple domain names and i cannot just block them with one.

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900