static IWebProxy GetDefaultWebProxy() { WebProxy p = null; #if CONFIGURATION_DEP DefaultProxySection sec = ConfigurationManager.GetSection("system.net/defaultProxy") as DefaultProxySection; if (sec == null) { return(GetSystemWebProxy()); } ProxyElement pe = sec.Proxy; if ((pe.UseSystemDefault != ProxyElement.UseSystemDefaultValues.False) && (pe.ProxyAddress == null)) { p = (WebProxy)GetSystemWebProxy(); } else { p = new WebProxy(); } if (pe.ProxyAddress != null) { p.Address = pe.ProxyAddress; } if (pe.BypassOnLocal != ProxyElement.BypassOnLocalValues.Unspecified) { p.BypassProxyOnLocal = (pe.BypassOnLocal == ProxyElement.BypassOnLocalValues.True); } #endif return(p); }
static IWebProxy GetDefaultWebProxy () { #if CONFIGURATION_DEP DefaultProxySection sec = ConfigurationManager.GetSection ("system.net/defaultProxy") as DefaultProxySection; WebProxy p; if (sec == null) return GetSystemWebProxy (); ProxyElement pe = sec.Proxy; if ((pe.UseSystemDefault != ProxyElement.UseSystemDefaultValues.False) && (pe.ProxyAddress == null)) { IWebProxy proxy = GetSystemWebProxy (); if (!(proxy is WebProxy)) return proxy; p = (WebProxy) proxy; } else p = new WebProxy (); if (pe.ProxyAddress != null) p.Address = pe.ProxyAddress; if (pe.BypassOnLocal != ProxyElement.BypassOnLocalValues.Unspecified) p.BypassProxyOnLocal = (pe.BypassOnLocal == ProxyElement.BypassOnLocalValues.True); foreach(BypassElement elem in sec.BypassList) p.BypassArrayList.Add(elem.Address); return p; #else return GetSystemWebProxy (); #endif }
public string УстановитьDefaultProxy() { Configuration roamingConfig = ConfigurationManager .OpenExeConfiguration(ConfigurationUserLevel.None); ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap { ExeConfigFilename = roamingConfig.FilePath }; // Get the mapped configuration file. Configuration config = ConfigurationManager.OpenMappedExeConfiguration( configFileMap, ConfigurationUserLevel.None); string sectionName = "system.net/defaultProxy"; if (!(config.GetSection(sectionName) is DefaultProxySection ProxySection)) { ProxySection = new DefaultProxySection(); config.Sections.Add(sectionName, ProxySection); } ProxySection.UseDefaultCredentials = true; ProxySection.Enabled = true; config.Save(ConfigurationSaveMode.Full, true); ConfigurationManager.RefreshSection(sectionName); return(config.FilePath); }
private static IWebProxy GetDefaultProxy_UsingOldMonoCode() { DefaultProxySection defaultProxySection = ConfigurationManager.GetSection("system.net/defaultProxy") as DefaultProxySection; if (defaultProxySection == null) { Console.WriteLine("DefaultProxySectionInternal: defaultProxySection is null returning GetSystemWebProxy()"); return(GetSystemWebProxy()); } ProxyElement proxy = defaultProxySection.Proxy; WebProxy webProxy; if (proxy.UseSystemDefault != 0 && proxy.ProxyAddress == (Uri)null) { Console.WriteLine("DefaultProxySectionInternal: defaultProxySection not being used"); IWebProxy systemWebProxy = GetSystemWebProxy(); if (!(systemWebProxy is WebProxy)) { Console.WriteLine("DefaultProxySectionInternal: return GetSystemWebProxy(). system proxy type: {0}", systemWebProxy.GetType().FullName); return(systemWebProxy); } webProxy = (WebProxy)systemWebProxy; } else { webProxy = new WebProxy(); } if (proxy.ProxyAddress != (Uri)null) { Console.WriteLine("DefaultProxySectionInternal: setting proxyAddress {0}", proxy.ProxyAddress); webProxy.Address = proxy.ProxyAddress; } if (proxy.BypassOnLocal != ProxyElement.BypassOnLocalValues.Unspecified) { webProxy.BypassProxyOnLocal = (proxy.BypassOnLocal == ProxyElement.BypassOnLocalValues.True); } foreach (BypassElement bypass in defaultProxySection.BypassList) { webProxy.BypassArrayList.Add(bypass.Address); } return(webProxy); }