Make a web browser that only allows certain web sites in C#
The WebBrowser control is a full-featured web browser in a control that you can place on your form. You can use its Navigate method to make the browser go to a specific URL. You can also catch its Navigating event to decide whether to allow the browser to visit a site.
In this example, you can enter a URL in the TextBox and click Go to make the browser try to visit that site. Here's how the program navigates to the site you enter:
// Try to navigate to the entered URL.The program uses the following code to allow the browser to only go to the www.CSharpHelper.com web site.
private void btnGo_Click(object sender, EventArgs e)
{
webBrowser1.Navigate(txtUrl.Text);
}
// Verify that this is an allowed web site.To test the program, you can enter another web site (such as Google or Yahoo) and click Go. You can also go to the CSharpHelper web site's Books page and click the links to try to go to Amazon.com or Amazon.co.uk.
private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
if (e.Url.Host != "www.csharphelper.com")
{
e.Cancel = true;
MessageBox.Show("This web site is prohibited",
"Prohibited", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
}
}


i have learnt more about this post so I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me
Reply to this