Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
So im trying to connect to the internet using my WebBrowser control in C# and what I do is that I change the Registry Editor to change the Proxy settings in Internet Explorer but it doesnt actually apply the proxy server until I restart the application. For example..

1. I start the application and connect with the current proxy settings
2. I change the settings while the application is still open (I do this manually and not in the application)
3. I make sure that the settings has changed in the Registry Editor (and it has)
4. I reload the Load function by pressing the load button.
5. And its still the same proxy IP as the first time I started the application.


How do I make it to where if I change the proxy settings and refresh it, it reloads the website with the new proxy?

private void Load()
{
    //Disable the error messages.
    myWebBrowser.ScriptErrorsSuppressed = true;

    //Navigate to the cmyip website.
    myWebBrowser.Navigate("http://www.cmyip.org");
}

private void SetProxy(string Proxy)
{

    string key = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";

    RegistryKey RegKey = Registry.CurrentUser.OpenSubKey(key, true);
    RegKey.SetValue("ProxyServer", Proxy);
    if (Proxy == "")
    {
        RegKey.SetValue("ProxyEnable", 0);
    }
    else
    {
        RegKey.SetValue("ProxyEnable", 1);
    }

}


What I have tried:

I've tried inizializing a new instance of the webbrowser but that didnt work, I've also googled the issue.
Posted
Updated 1-May-17 6:49am

1 solution

You're hacking the setting directly into the registry, but the application doesn't know this stuff changed. The WebBrowser control only loads the proxy information once, when the control is created.

You have to change the proxy information using the functions in WinInet.dll, example of which you can find here[^]. It's not a simple, straightforward thing to do.
 
Share this answer
 

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