Click here to Skip to main content
15,887,988 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm trying to develop an application, where user can load a proxy list and software should navigate to a page with different IP's. I'm using some registry settings to do that. But the problem is that when i try to change the IP address it remains the same, in "Internet Options" the IP has changed but on the web page which i'm navigating to, is still shown the IP I navigated first time with. Any solutions about that? or maybe, You have a better solution about this situation. Please suggest something. I tried "httprequest" some moments ago, but that was maddeningly unhelpful. Or maybe i did "httprequest" in a bad way. Any suggestions?

What I have tried:

private void BrowseProxy_Click(object sender, EventArgs e)  
     {
        openFileDialog1.ShowDialog();

        ProxySrcTBX.Text = openFileDialog1.FileName;

        using (StreamReader r = new StreamReader(ProxySrcTBX.Text))
        {
            string line;
            while ((line = r.ReadLine()) != null)
            {
                ProxyCount++;
            }
            r.Close();
        }

        try { Proxy = File.ReadAllLines(ProxySrcTBX.Text); }
        catch (Exception Exception) { MessageBox.Show(Exception.ToString()); }
    }

   private void SetProxy(string Proxy)
    {
        string key = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";

        RegistryKey RegKey = Registry.CurrentUser.OpenSubKey(key, true);
        RegKey.SetValue("ProxyServer", Proxy);
        RegKey.SetValue("ProxyEnable", 1);
        RegKey.Close();

    }

  private void button6_Click(object sender, EventArgs e)
    {
        webBrowser1.ScriptErrorsSuppressed = true;
        SetProxy(Proxy[ProxyIndex]);
        label2.Text = Proxy[ProxyIndex];
        currentUri = new Uri("https://myip.ru");
        NavigateTo(currentUri);
    }
    public void NavigateTo(Uri url)
    {
        url = currentUri;
        webBrowser1.Navigate(url);
    }

   private void Dispose_Click(object sender, EventArgs e)
    {
        SetProxy("");
        string key = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
        RegistryKey RegKey = Registry.CurrentUser.OpenSubKey(key, true);
        RegKey.SetValue("ProxyEnable", 0);
        RegKey.Close();
        ProxyIndex++;
    }
Posted
Updated 27-Feb-17 1:53am

1 solution

There may be two reasons for such behaviour.

The first is that the page is not requested again but got from the cache. This can be only avoided by clearing the cache (see How to clear the cache when your application hosts a WebBrowser control in Visual C# .NET[^]).

The second reason might be that the WebBrowser control does not know that the registry has been changed. I don't know a solution for this besides restarting it (that is terminating your application and starting it again). However, it might help to dispose and re-create the browser control.

Note that the internet settings can be also set by code instead of changing the registry directly. See for example Journey Into Code: C# WebBrowser Control Proxy Authentication[^].
 
Share this answer
 
Comments
Nika Qantaria 1-Mar-17 8:01am    
Thank you!

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