У меня есть конфигурационный файл для моего приложения, моя app.config, как показано нижеКак прочитать файл app.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="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"];
получит «192.168.130.5»,
Как получить все прокси настройки в разделе system.net в C#?
Обновлено: я изменил конфиг к следующему и получить его:
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>
Спасибо. но ConfigurationManager.GetSection («прокси») имеет значение – toosensitive
Вы пробовали первое предложение? – edesr
var proxy = System.Web.Configuration.WebConfigurationManager.GetSection ("system.net/defaultProxy") как System.Net.Configuration.DefaultProxySection – edesr