none
Block webbrowser from accessing webpages in c# RRS feed

  • Question

  • I have a problem at work.

    I have a WPF-client. Code in C#.
    I have a database with url's. We want to block the webbrowser from reaching these webpages.
    We have different users. They login to the WPF-client. We want to block different url's for different users.
    This shall work for different webbrowsers to.

    I have looked at the host file. But i think it is one host file for every user on the computer.

    Does webbrowser like IE, Firefox, Chrome, Opera have a API that i can use for this?

    I would be really grateful for some advice about this.


    Systemdeveloper .Net

    Tuesday, August 20, 2013 9:04 PM

Answers

  • Dear Oscar,

    I think we can use this workaround. When I user login on this machine, we can

    modify / load the host file according to different type of user. When the user sign out

    this application, we recover the original host file.

    In addition, here is another solution, we can use windows firewall to solve this issue.

    Here are some references about this solution.

    #Making a webpage-blocking application in C#

    http://stackoverflow.com/questions/8611478/making-a-webpage-blocking-application-in-c-sharp

    #Controlling Windows Firewall using C# via COM Interop

    http://www.shafqatahmed.com/2008/01/controlling-win.html

    If I misunderstood, please feel free to let me know.

    Have a great day.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    • Edited by Yang,Chenfei Friday, August 23, 2013 3:02 PM
    • Marked as answer by Yang,Chenfei Tuesday, August 27, 2013 1:23 PM
    Friday, August 23, 2013 3:01 PM

All replies

  • Hi Oscar,

    According to your description, I understood there is an issue regarding how to block web

    browser from accessing webpages in c#.

    As you said, we can use host file to block webpages. You are right.

    In fact, blocking websites through the HOSTS file is an effective way to do it because it blocks

    it across all the browsers (block sites in Internet explorer, Google Chrome, Firefox).

    We can change the host file to block webpages. Now let’s add an entry to block,

    127.0.0.1 www.bing.com

    We are telling our local machine that Bing actually exists on the local machine. Any request for

    www.bing.com will be directed to the local machine and therefore effectively blocked. You

    could also use the IP of another website if you wanted to be creative.

    I recommended some articles to you. These articles are related to use host file to block

    Webpages.

    #How to Block Websites By Editing the HOSTS File in Windows

    http://www.guidingtech.com/4868/edit-hosts-file-block-websites/

    http://www.overclock.net/t/44143/how-to-use-the-hosts-file-to-block-websites-in-windows

    If you need more assistance, please feel free to let me know.

    Regards,


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.




    • Edited by Yang,Chenfei Thursday, August 22, 2013 2:35 AM format
    Thursday, August 22, 2013 1:49 AM
  • I cant use host file. Which webpages we block depends on who is logged in as user in the wpf-client.

    When the computer start, we start a wpf-client. A user have to loggin to the wpf-client. We run the wpf-client in the background. Then it is the client that do the blocking of webpages, blocking of applications. Shot down aplication when the specified usage time has run out and more function


    Andersson. Systemdeveloper .Net

    Friday, August 23, 2013 6:26 AM
  • Dear Oscar,

    I think we can use this workaround. When I user login on this machine, we can

    modify / load the host file according to different type of user. When the user sign out

    this application, we recover the original host file.

    In addition, here is another solution, we can use windows firewall to solve this issue.

    Here are some references about this solution.

    #Making a webpage-blocking application in C#

    http://stackoverflow.com/questions/8611478/making-a-webpage-blocking-application-in-c-sharp

    #Controlling Windows Firewall using C# via COM Interop

    http://www.shafqatahmed.com/2008/01/controlling-win.html

    If I misunderstood, please feel free to let me know.

    Have a great day.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    • Edited by Yang,Chenfei Friday, August 23, 2013 3:02 PM
    • Marked as answer by Yang,Chenfei Tuesday, August 27, 2013 1:23 PM
    Friday, August 23, 2013 3:01 PM
  • You cannot edit the host file unless you are administrator so "normal" users would have a problem with the application attempting to modify it.

    Lloyd Sheen

    Friday, August 23, 2013 4:23 PM