Enabling / disabling a proxy application does not work properly with IE

I have a really strange situation here: I wrote an application that, among other things, switches the connection proxy from one to another and vice versa. This is done by changing the value in the registry:

public void SetUpProxy(string proxy, bool enable)
{
    RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
    if (proxy != null)
        key.SetValue("ProxyServer", proxy);
    key.SetValue("ProxyEnable", enable ? 1 : 0);
    key.Close();
}

When I ask to enable the proxy in my application, the first thing it does is connect to the ftp server, download the file, then activate the proxy server (the download will not work with the proxy server). Everything works fine - until I started Internet Explorer.
For example: if I run my application, let it turn on the proxy server, and then let it turn off the proxy server - everything works fine. But if I turn on the proxy server, then start IE , turn off the proxy and try turning it on again, it does not work - the application cannot connect to the ftp server, because somehow it uses the proxy server, although the value is in the registry 0!
I hope I managed to explain this correctly. My question is: why is this happening and how can I fix it?

: WebClient . , client.Proxy.GetProxy(myUri) Uri, , IE, " http://theUriFromIE".

+3
6

- WebClient null .

+1

, , , Windows XP, , Internet Explorer .

, -, IE , .

, Windows Vista .

:

. # - , , System.Net.GlobalProxySelection. System.Net.WebProxy.

- , , P/Invoke WinAPI WinHttpSetDefaultProxyConfiguration.

Microsoft. - Internet Explorer.

+1

, FtpWebRequest, .Proxy, , , .IsBypassed. , , False ( ) , , , IE.

: er, IsBypassed True ( - , , , ).

2: . , :

<configuration>
  <system.net>
    <defaultProxy>
      <proxy autoDetect="false" />
    </defaultProxy>
  </system.net>
</configuration>

autoDetect , - IE, false .

+1

, , .

-, API- InternetSetOption WinINET.

   if (InternetSetOptionList((IntPtr)0, INTERNET_OPTION_PER_CONNECTION_OPTION, ref Request, size))
    {
        // Success. Announce to the world that we've changed the proxy
       InternetSetOption((IntPtr)0, INTERNET_OPTION_PROXY_SETTINGS_CHANGED, (IntPtr)0, 0);
    }
0

EricLaw, - wininet.

The code that I use in my C ++ application is slightly modified to tell IE to reload its proxy settings:

     // ... code changing registry settings...
InternetSetOption(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
InternetSetOption(NULL, INTERNET_OPTION_REFRESH, NULL, 0);

Going through wininet.h, I never saw links to

INTERNET_OPTION_PROXY_SETTINGS_CHANGED 

therefore not sure where it came from.

0
source

I used bottom udpate 2. Its work. Thanks to everyone.

Update 2: here is another assumption. Try putting this in your application configuration file and then recompiling it:

                 

-3
source

Source: https://habr.com/ru/post/1717137/


All Articles