I have config file for my app, my app.config is as below
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="System.Configuration.IgnoreSectionHandler" />
</configSections>
<appSettings>
<add key="log4net.Config" value="log4netConfig.xml" />
<add key="proxyaddress" value="192.168.130.5"/>
</appSettings>
<system.net>
<defaultProxy enabled ="true" useDefaultCredentials = "true">
<proxy autoDetect="false"
bypassonlocal="true"
proxyaddress="192.168.130.6"
scriptLocation="https://ws.mycompany.com/proxy.dat"
usesystemdefault="true"
/>
</defaultProxy>
</system.net>
</configuration>
var proxy= ConfigurationManager.AppSettings["proxyaddress"];
will get "192.168.130.5",
How to get all proxy settings in system.net section in c#?
Updated: I changed my config to the following and get it:
string proxyURLAddr = ConfigurationManager.AppSettings["proxyaddress"];
Config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="System.Configuration.IgnoreSectionHandler" />
</configSections>
<appSettings>
<add key="log4net.Config" value="log4netConfig.xml" />
<add key="proxyaddress" value=""/>
</appSettings>
<system.net>
<defaultProxy enabled ="true" useDefaultCredentials = "true">
<proxy usesystemdefault ="True" bypassonlocal="False"/>
</defaultProxy>
</system.net>
</configuration>