locked
prevent webbrowser from navigating to websites RRS feed

  • Question

  • I am working with vb.net to making a form that prevents the web broswer on windows internet explorer from navigating to certian pages. The code can't just work on internet explorer because I could make a program with a web browser that navigates. It has to prevent the web browser itself from navigating.

    Any help?

    Friday, September 2, 2011 6:54 PM

Answers

  • Hi PLM1776,

    Some suggestions here for you to try.

    # Manually block them from Browser settings.
    For Instance, Internet Explorer
    Go to tools -> Internet Options -> Security -> Restricted sites, type the website url you want to block.

    # Usage of some Networking APIs
    For further assistance on how to do it, please refer to: http://social.msdn.microsoft.com/Forums/en-US/netfxnetcom/threads/ 

    # Writing hosts file which maps domain name to IP addresses to block Internet resource
    It has been introduced in Mike's post. Be aware this operation requires high privilege, and takes certain risk, you better back up first before doing this.

    #Hook
    This would be more complicated but lower program security and performance, which is not recommended.

    Best Regards,


    Kee Poppy [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Edited by Kee PoppyModerator Thursday, September 8, 2011 7:32 AM
    • Proposed as answer by spajky1 Thursday, September 8, 2011 10:28 AM
    • Marked as answer by PLM1776 Saturday, September 10, 2011 1:55 AM
    Thursday, September 8, 2011 7:31 AM
    Moderator

All replies

  • You can simply prevent Webbrowser from navigating by handling 'navigating' event like this:

    Private Sub WebBrowser1_navigating(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating
            e.Cancel = True
    End Sub

    You can also define your custom conditions within an if-then block in navigating event then set "cancel = true".

    HTH.


    Best regards, Saygılarımla, Onur Güzel

    Yazgeliştir Forumları VB.NET / C# Süper Moderatorü.

    Microsoft Haber Grupları Profilim (VB.NET)

    Friday, September 2, 2011 7:40 PM
  • you don't understand

    i want to prevent windows internet explorer from going to certian sites but the code has to have something to do with the webbrowser. For example, this is the code I have:

    Dim

    p As Process() = System.Diagnostics.Process.GetProcesses()

     

    For i As Integer = 0 To p.Length - 1

    'I am going to use the example "Google - Windows Internet Explorer"

     

    If p(i).MainWindowTitle = "Google - Windows Internet Explorer" Then

    p(i).Kill()

     

    End If

    Next

    This code blockes the internet explorer from the google home page

    i don't want to prevent just the internet explorer from these websites, but every program that has a webbrowser to those sites.

    Basically, I want to make a program that detects if a webbrowser is running and if it is, then see what website it is on. If it is on a website that is prohibited, than it immidiatly closes the program that is running the webbrowser.

    Friday, September 2, 2011 9:13 PM

  • You might try modifying the hosts file, as shown in this thread: http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/e1d125fa-2763-4a7d-bed1-8e5a5eb4b467/
     

    --
    Mike
    Saturday, September 3, 2011 2:00 AM
  • You making phishing filter? There is no way to 'go and detect' You must got some source of beware sites! And then make program check if that list contains current page if not ok if yes then show some alert, I'm right? Let's say you have a textfile with beware sites,then you must read it with streamwriter and write it to textbox and then:

     

    Private Sub WebBrowser1_Navigating(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating
    if TextBox.text.contains (webbrowser.url) Then
    ' command if you try to go malicious site
    else
    'nothing
    End Sub
    
    'or its maybe
    'textbox.contains (webbrowser.url._____) - im not sure and im too lazy to open VB now...you will see when you going to type!
    


     


    • Edited by spajky1 Saturday, September 3, 2011 9:23 PM
    Saturday, September 3, 2011 9:21 PM
  • If the code can answer these questions then it will probaby will answer my question:

    How do you prevent Windows Internet Explorer from going to certian sites?

    How to keep all Internet sources like google chrome or firefox from going to certian sites?

    I want to answer both of these questions with the same code



    • Edited by PLM1776 Monday, September 5, 2011 5:28 PM
    Monday, September 5, 2011 1:48 AM
  • Hi PLM1776,

    Some suggestions here for you to try.

    # Manually block them from Browser settings.
    For Instance, Internet Explorer
    Go to tools -> Internet Options -> Security -> Restricted sites, type the website url you want to block.

    # Usage of some Networking APIs
    For further assistance on how to do it, please refer to: http://social.msdn.microsoft.com/Forums/en-US/netfxnetcom/threads/ 

    # Writing hosts file which maps domain name to IP addresses to block Internet resource
    It has been introduced in Mike's post. Be aware this operation requires high privilege, and takes certain risk, you better back up first before doing this.

    #Hook
    This would be more complicated but lower program security and performance, which is not recommended.

    Best Regards,


    Kee Poppy [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Edited by Kee PoppyModerator Thursday, September 8, 2011 7:32 AM
    • Proposed as answer by spajky1 Thursday, September 8, 2011 10:28 AM
    • Marked as answer by PLM1776 Saturday, September 10, 2011 1:55 AM
    Thursday, September 8, 2011 7:31 AM
    Moderator
  • For what it's worth, please consider the following:

    What you describe is an outbound URL request filter.  As previously mentioned, each web browser is likely to support this feature, but I understand the desire to control this at a lower level than an individual browser.

    In a network environment, this is functionality which does not belong on any PC, but rather, it is work to be performed by your network gateway/firewall.  Only if the PC has its own direct internet connection (e.g. directly attached via USB to DSL Modem) would you possibly need to enforce URL filtering at the application level; and then only if the particular modem in question did not support the URL filtering itself internally.

    The other option is to place uncontrollable clients on a unique network subnet which does not have direct access to the Internet.  You can then provide a proxy server on this subnet which can route requests to a network segment which does have Internet access, while at the same time filtering those requests and reporting on those which are considered illicit.

    In most cases I would say that this is most easily and reliably achieved by purchasing a small firewall appliance (well, an appliance appropriate to your network's size) and routing all questionable clients through this device in order to access the Internet.

    Doing it in software would most likely require the Win32 network API hooks (mentioned by Poppy) and a lot of network post processing which is likely to have a noticable negative performance impact on all network operations for the PC running the application.  I would consider this to be an "expert-level" code project and am not entirely sure that VB.Net would even be the most appropriate platform for such a thing.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
    Thursday, September 8, 2011 4:20 PM
    Moderator