jolly
jolly

Reputation: 287

Block Site in Web Browser

How to block all website in webbrowser control except facebook.com?? example:

private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
   if (webBrowser1.Url.ToString() == "All site from facebook.com")
   {
   }
   else
   {
      MessageBox.Show("Site Blocked");
      webBrowser.Navigated("Http://google.com");
   }
}

Upvotes: 0

Views: 1795

Answers (2)

Ry-
Ry-

Reputation: 224862

Handle Navigating as you're already doing, but cancel it if the URL isn't from Facebook:

e.Cancel = !e.Url.Host.EndsWith(".facebook.com");

Upvotes: 8

Gregory Corneta
Gregory Corneta

Reputation: 1

There are two properties in the WebBrowserNavigatingEventArgs class that can help you. One of them is Url and the other is Cancel.

Note that Url is of Uri type, so you can look for "facebook.com" easily. If you find "facebook.com" then you set the Cancel to true.

For more information take a look at this: http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowsernavigatingeventargs.url.aspx

Upvotes: 0

Related Questions