static internal DefaultProxySectionInternal GetSection() { lock (DefaultProxySectionInternal.ClassSyncObject) { DefaultProxySection section = PrivilegedConfigurationManager.GetSection(ConfigurationStrings.DefaultProxySectionPath) as DefaultProxySection; if (section == null) { return(null); } try { return(new DefaultProxySectionInternal(section)); } catch (Exception exception) { if (NclUtilities.IsFatal(exception)) { throw; } throw new ConfigurationErrorsException(SR.GetString(SR.net_config_proxy), exception); } catch { throw new ConfigurationErrorsException(SR.GetString(SR.net_config_proxy), new Exception(SR.GetString(SR.net_nonClsCompliantException))); } } }
static internal DefaultProxySectionInternal GetSection() { lock (DefaultProxySectionInternal.ClassSyncObject) { #if MONO var res = new DefaultProxySectionInternal(); res.webProxy = GetDefaultProxy_UsingOldMonoCode(); return(res); #else DefaultProxySection section = PrivilegedConfigurationManager.GetSection(ConfigurationStrings.DefaultProxySectionPath) as DefaultProxySection; if (section == null) { return(null); } try { return(new DefaultProxySectionInternal(section)); } catch (Exception exception) { if (NclUtilities.IsFatal(exception)) { throw; } throw new ConfigurationErrorsException(SR.GetString(SR.net_config_proxy), exception); } #endif } }
protected override void Reset(ConfigurationElement parentElement) { DefaultProxySection section = new DefaultProxySection(); section.InitializeDefault(); base.Reset(section); }
internal static DefaultProxySectionInternal GetSection() { DefaultProxySectionInternal internal2; lock (ClassSyncObject) { DefaultProxySection section = System.Configuration.PrivilegedConfigurationManager.GetSection(ConfigurationStrings.DefaultProxySectionPath) as DefaultProxySection; if (section == null) { internal2 = null; } else { try { internal2 = new DefaultProxySectionInternal(section); } catch (Exception exception) { if (NclUtilities.IsFatal(exception)) { throw; } throw new ConfigurationErrorsException(System.SR.GetString("net_config_proxy"), exception); } } } return(internal2); }
// This allows us to prevent parent settings (machine.config) from propegating to higher config (app.config), unless // the higher config doesn't contain the section at all. That is, overriding defaultProxy is all-or-nothing. // Template from sseely. protected override void Reset(ConfigurationElement parentElement) { // Ignore the parentElement parameter by changing it to the default settings DefaultProxySection defaultElement = new DefaultProxySection(); // Initialize the parentElement to the right set of defaults (not needed now, // but this will avoid errors in the future if SetDefaults is ever overridden in this class. // ConfigurationElement::InitializeDefault is a no-op, so you aren’t hurting perf by anything // measurable. defaultElement.InitializeDefault(); // Finally, pass it to the base class to do the “right things” base.Reset(defaultElement); }
static IWebProxy GetDefaultProxy_UsingOldMonoCode() { #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 }
internal DefaultProxySectionInternal(DefaultProxySection section) { // If enabled is false, skip everything. if (!section.Enabled) { return; } // If nothing else is set, use the system default. if (section.Proxy.AutoDetect == ProxyElement.AutoDetectValues.Unspecified && section.Proxy.ScriptLocation == null && String.IsNullOrEmpty(section.Module.Type) && section.Proxy.UseSystemDefault != ProxyElement.UseSystemDefaultValues.True && section.Proxy.ProxyAddress == null && section.Proxy.BypassOnLocal == ProxyElement.BypassOnLocalValues.Unspecified && section.BypassList.Count == 0) { // Old-style indication to turn off the proxy. if (section.Proxy.UseSystemDefault == ProxyElement.UseSystemDefaultValues.False) { this.webProxy = new EmptyWebProxy(); // Intentionally ignoring UseDefaultCredentials in this case. return; } } else { // First, check out if we are using a different module type if (!String.IsNullOrEmpty(section.Module.Type)) { Type theType = Type.GetType(section.Module.Type, true, true); if ((theType.Attributes & TypeAttributes.VisibilityMask) != TypeAttributes.Public) { throw new ConfigurationErrorsException(SR.GetString(SR.net_config_proxy_module_not_public)); } // verify that its of the proper type of IWebProxy if (!typeof(IWebProxy).IsAssignableFrom(theType)) { throw new InvalidCastException(SR.GetString(SR.net_invalid_cast, theType.FullName, "IWebProxy")); } this.webProxy = (IWebProxy)Activator.CreateInstance( theType, BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, // Binder new object[0], // no arguments CultureInfo.InvariantCulture ); } else if (section.Proxy.UseSystemDefault == ProxyElement.UseSystemDefaultValues.True && section.Proxy.AutoDetect == ProxyElement.AutoDetectValues.Unspecified && section.Proxy.ScriptLocation == null) { } else { this.webProxy = new WebProxy(); } WebProxy tempProxy = this.webProxy as WebProxy; if (tempProxy != null) { if (section.Proxy.AutoDetect != ProxyElement.AutoDetectValues.Unspecified) { tempProxy.AutoDetect = section.Proxy.AutoDetect == ProxyElement.AutoDetectValues.True; } if (section.Proxy.ScriptLocation != null) { tempProxy.ScriptLocation = section.Proxy.ScriptLocation; } if (section.Proxy.BypassOnLocal != ProxyElement.BypassOnLocalValues.Unspecified) { tempProxy.BypassProxyOnLocal = section.Proxy.BypassOnLocal == ProxyElement.BypassOnLocalValues.True; } if (section.Proxy.ProxyAddress != null) { tempProxy.Address = section.Proxy.ProxyAddress; } int bypassListSize = section.BypassList.Count; if (bypassListSize > 0) { string[] bypassList = new string[section.BypassList.Count]; for (int index = 0; index < bypassListSize; ++index) { bypassList[index] = section.BypassList[index].Address; } tempProxy.BypassList = bypassList; } // Wrap it if type not explicitly specified in Module. if (section.Module.Type == null) { this.webProxy = new WebRequest.WebProxyWrapper(tempProxy); } } } // Now apply UseDefaultCredentials if there's a proxy. if (this.webProxy != null && section.UseDefaultCredentials) { this.webProxy.Credentials = SystemNetworkCredential.defaultCredential; } }
internal DefaultProxySectionInternal(DefaultProxySection section) { // If enabled is false, skip everything. if (!section.Enabled) { return; } // If nothing else is set, use the system default. if (section.Proxy.AutoDetect == ProxyElement.AutoDetectValues.Unspecified && section.Proxy.ScriptLocation == null && String.IsNullOrEmpty(section.Module.Type) && section.Proxy.UseSystemDefault != ProxyElement.UseSystemDefaultValues.True && section.Proxy.ProxyAddress == null && section.Proxy.BypassOnLocal == ProxyElement.BypassOnLocalValues.Unspecified && section.BypassList.Count == 0) { // Old-style indication to turn off the proxy. if (section.Proxy.UseSystemDefault == ProxyElement.UseSystemDefaultValues.False) { this.webProxy = new EmptyWebProxy(); // Intentionally ignoring UseDefaultCredentials in this case. return; } // Suspend impersonation. try { new SecurityPermission(SecurityPermissionFlag.ControlPrincipal | SecurityPermissionFlag.UnmanagedCode).Assert(); #if !FEATURE_PAL using(WindowsIdentity.Impersonate(IntPtr.Zero)) #endif // !FEATURE_PAL { CodeAccessPermission.RevertAssert(); this.webProxy = new WebRequest.WebProxyWrapper(new WebProxy(true)); } } catch { throw; } } else { // First, check out if we are using a different module type if (!String.IsNullOrEmpty(section.Module.Type)) { Type theType = Type.GetType(section.Module.Type, true, true); if ((theType.Attributes & TypeAttributes.VisibilityMask) != TypeAttributes.Public) throw new ConfigurationErrorsException(SR.GetString(SR.net_config_proxy_module_not_public)); // verify that its of the proper type of IWebProxy if (!typeof(IWebProxy).IsAssignableFrom(theType)) { throw new InvalidCastException(SR.GetString(SR.net_invalid_cast, theType.FullName, "IWebProxy")); } this.webProxy = (IWebProxy)Activator.CreateInstance( theType, BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, // Binder new object[0], // no arguments CultureInfo.InvariantCulture ); } else if (section.Proxy.UseSystemDefault == ProxyElement.UseSystemDefaultValues.True && section.Proxy.AutoDetect == ProxyElement.AutoDetectValues.Unspecified && section.Proxy.ScriptLocation == null) { // Suspend impersonation. This setting is deprecated but required for Everett compat. try { new SecurityPermission(SecurityPermissionFlag.ControlPrincipal | SecurityPermissionFlag.UnmanagedCode).Assert(); #if !FEATURE_PAL using(WindowsIdentity.Impersonate(IntPtr.Zero)) #endif // !FEATURE_PAL { CodeAccessPermission.RevertAssert(); this.webProxy = new WebProxy(false); } } catch { throw; } } else { this.webProxy = new WebProxy(); } WebProxy tempProxy = this.webProxy as WebProxy; if (tempProxy != null) { if (section.Proxy.AutoDetect != ProxyElement.AutoDetectValues.Unspecified) { tempProxy.AutoDetect = section.Proxy.AutoDetect == ProxyElement.AutoDetectValues.True; } if (section.Proxy.ScriptLocation != null) { tempProxy.ScriptLocation = section.Proxy.ScriptLocation; } if (section.Proxy.BypassOnLocal != ProxyElement.BypassOnLocalValues.Unspecified) { tempProxy.BypassProxyOnLocal = section.Proxy.BypassOnLocal == ProxyElement.BypassOnLocalValues.True; } if (section.Proxy.ProxyAddress != null) { tempProxy.Address = section.Proxy.ProxyAddress; } int bypassListSize = section.BypassList.Count; if (bypassListSize > 0) { string[] bypassList = new string[section.BypassList.Count]; for (int index = 0; index < bypassListSize; ++index) { bypassList[index] = section.BypassList[index].Address; } tempProxy.BypassList = bypassList; } // Wrap it if type not explicitly specified in Module. if (section.Module.Type == null) { this.webProxy = new WebRequest.WebProxyWrapper(tempProxy); } } } // Now apply UseDefaultCredentials if there's a proxy. if (this.webProxy != null && section.UseDefaultCredentials) { this.webProxy.Credentials = SystemNetworkCredential.defaultCredential; } }
// This allows us to prevent parent settings (machine.config) from propegating to higher config (app.config), unless // the higher config doesn't contain the section at all. That is, overriding defaultProxy is all-or-nothing. // Template from Microsoft. protected override void Reset(ConfigurationElement parentElement) { // Ignore the parentElement parameter by changing it to the default settings DefaultProxySection defaultElement = new DefaultProxySection(); // Initialize the parentElement to the right set of defaults (not needed now, // but this will avoid errors in the future if SetDefaults is ever overridden in this class. // ConfigurationElement::InitializeDefault is a no-op, so you aren’t hurting perf by anything // measurable. defaultElement.InitializeDefault(); // Finally, pass it to the base class to do the “right things” base.Reset(defaultElement); }
internal DefaultProxySectionInternal(DefaultProxySection section) { System.Net.WebProxy proxy; if (!section.Enabled) { return; } if ((((section.Proxy.AutoDetect == ProxyElement.AutoDetectValues.Unspecified) && (section.Proxy.ScriptLocation == null)) && (string.IsNullOrEmpty(section.Module.Type) && (section.Proxy.UseSystemDefault != ProxyElement.UseSystemDefaultValues.True))) && (((section.Proxy.ProxyAddress == null) && (section.Proxy.BypassOnLocal == ProxyElement.BypassOnLocalValues.Unspecified)) && (section.BypassList.Count == 0))) { if (section.Proxy.UseSystemDefault == ProxyElement.UseSystemDefaultValues.False) { this.webProxy = new EmptyWebProxy(); return; } try { new SecurityPermission(SecurityPermissionFlag.ControlPrincipal | SecurityPermissionFlag.UnmanagedCode).Assert(); using (WindowsIdentity.Impersonate(IntPtr.Zero)) { CodeAccessPermission.RevertAssert(); this.webProxy = new WebRequest.WebProxyWrapper(new System.Net.WebProxy(true)); } goto Label_030E; } catch { throw; } } if (!string.IsNullOrEmpty(section.Module.Type)) { Type c = Type.GetType(section.Module.Type, true, true); if ((c.Attributes & TypeAttributes.NestedFamORAssem) != TypeAttributes.Public) { throw new ConfigurationErrorsException(System.SR.GetString("net_config_proxy_module_not_public")); } if (!typeof(IWebProxy).IsAssignableFrom(c)) { throw new InvalidCastException(System.SR.GetString("net_invalid_cast", new object[] { c.FullName, "IWebProxy" })); } this.webProxy = (IWebProxy)Activator.CreateInstance(c, BindingFlags.CreateInstance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new object[0], CultureInfo.InvariantCulture); } else { if (((section.Proxy.UseSystemDefault == ProxyElement.UseSystemDefaultValues.True) && (section.Proxy.AutoDetect == ProxyElement.AutoDetectValues.Unspecified)) && (section.Proxy.ScriptLocation == null)) { try { new SecurityPermission(SecurityPermissionFlag.ControlPrincipal | SecurityPermissionFlag.UnmanagedCode).Assert(); using (WindowsIdentity.Impersonate(IntPtr.Zero)) { CodeAccessPermission.RevertAssert(); this.webProxy = new System.Net.WebProxy(false); } goto Label_0209; } catch { throw; } } this.webProxy = new System.Net.WebProxy(); } Label_0209: proxy = this.webProxy as System.Net.WebProxy; if (proxy != null) { if (section.Proxy.AutoDetect != ProxyElement.AutoDetectValues.Unspecified) { proxy.AutoDetect = section.Proxy.AutoDetect == ProxyElement.AutoDetectValues.True; } if (section.Proxy.ScriptLocation != null) { proxy.ScriptLocation = section.Proxy.ScriptLocation; } if (section.Proxy.BypassOnLocal != ProxyElement.BypassOnLocalValues.Unspecified) { proxy.BypassProxyOnLocal = section.Proxy.BypassOnLocal == ProxyElement.BypassOnLocalValues.True; } if (section.Proxy.ProxyAddress != null) { proxy.Address = section.Proxy.ProxyAddress; } int count = section.BypassList.Count; if (count > 0) { string[] strArray = new string[section.BypassList.Count]; for (int i = 0; i < count; i++) { strArray[i] = section.BypassList[i].Address; } proxy.BypassList = strArray; } if (section.Module.Type == null) { this.webProxy = new WebRequest.WebProxyWrapper(proxy); } } Label_030E: if ((this.webProxy != null) && section.UseDefaultCredentials) { this.webProxy.Credentials = SystemNetworkCredential.defaultCredential; } }
internal DefaultProxySectionInternal(DefaultProxySection section) { System.Net.WebProxy proxy; if (!section.Enabled) { return; } if ((((section.Proxy.AutoDetect == ProxyElement.AutoDetectValues.Unspecified) && (section.Proxy.ScriptLocation == null)) && (string.IsNullOrEmpty(section.Module.Type) && (section.Proxy.UseSystemDefault != ProxyElement.UseSystemDefaultValues.True))) && (((section.Proxy.ProxyAddress == null) && (section.Proxy.BypassOnLocal == ProxyElement.BypassOnLocalValues.Unspecified)) && (section.BypassList.Count == 0))) { if (section.Proxy.UseSystemDefault == ProxyElement.UseSystemDefaultValues.False) { this.webProxy = new EmptyWebProxy(); return; } try { new SecurityPermission(SecurityPermissionFlag.ControlPrincipal | SecurityPermissionFlag.UnmanagedCode).Assert(); using (WindowsIdentity.Impersonate(IntPtr.Zero)) { CodeAccessPermission.RevertAssert(); this.webProxy = new WebRequest.WebProxyWrapper(new System.Net.WebProxy(true)); } goto Label_030E; } catch { throw; } } if (!string.IsNullOrEmpty(section.Module.Type)) { Type c = Type.GetType(section.Module.Type, true, true); if ((c.Attributes & TypeAttributes.NestedFamORAssem) != TypeAttributes.Public) { throw new ConfigurationErrorsException(System.SR.GetString("net_config_proxy_module_not_public")); } if (!typeof(IWebProxy).IsAssignableFrom(c)) { throw new InvalidCastException(System.SR.GetString("net_invalid_cast", new object[] { c.FullName, "IWebProxy" })); } this.webProxy = (IWebProxy) Activator.CreateInstance(c, BindingFlags.CreateInstance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new object[0], CultureInfo.InvariantCulture); } else { if (((section.Proxy.UseSystemDefault == ProxyElement.UseSystemDefaultValues.True) && (section.Proxy.AutoDetect == ProxyElement.AutoDetectValues.Unspecified)) && (section.Proxy.ScriptLocation == null)) { try { new SecurityPermission(SecurityPermissionFlag.ControlPrincipal | SecurityPermissionFlag.UnmanagedCode).Assert(); using (WindowsIdentity.Impersonate(IntPtr.Zero)) { CodeAccessPermission.RevertAssert(); this.webProxy = new System.Net.WebProxy(false); } goto Label_0209; } catch { throw; } } this.webProxy = new System.Net.WebProxy(); } Label_0209: proxy = this.webProxy as System.Net.WebProxy; if (proxy != null) { if (section.Proxy.AutoDetect != ProxyElement.AutoDetectValues.Unspecified) { proxy.AutoDetect = section.Proxy.AutoDetect == ProxyElement.AutoDetectValues.True; } if (section.Proxy.ScriptLocation != null) { proxy.ScriptLocation = section.Proxy.ScriptLocation; } if (section.Proxy.BypassOnLocal != ProxyElement.BypassOnLocalValues.Unspecified) { proxy.BypassProxyOnLocal = section.Proxy.BypassOnLocal == ProxyElement.BypassOnLocalValues.True; } if (section.Proxy.ProxyAddress != null) { proxy.Address = section.Proxy.ProxyAddress; } int count = section.BypassList.Count; if (count > 0) { string[] strArray = new string[section.BypassList.Count]; for (int i = 0; i < count; i++) { strArray[i] = section.BypassList[i].Address; } proxy.BypassList = strArray; } if (section.Module.Type == null) { this.webProxy = new WebRequest.WebProxyWrapper(proxy); } } Label_030E: if ((this.webProxy != null) && section.UseDefaultCredentials) { this.webProxy.Credentials = SystemNetworkCredential.defaultCredential; } }