如何从 web.config 中的 system.net 部分读取 defaultProxy 设置的值? [英] How can I read the values of the defaultProxy settings from the system.net section in a web.config?

查看:61
本文介绍了如何从 web.config 中的 system.net 部分读取 defaultProxy 设置的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在运行时读取我的默认代理设置的值,但我似乎找不到任何这样做的方法.关于如何设置默认代理有很多相关的答案(例如 如何在 defaultProxy 配置设置中传递凭据?),但我正在寻找如何读取这些设置.

I am trying to read the values of my default proxy settings at runtime, but I can't seem to find any way of doing so. There are plenty of related answers on how to set a default proxy (e.g. How to pass credentials in defaultProxy config setting?), but I'm looking for how to read these settings.

这背后的原因是我们有时会打开代理,以便我们可以使用 Fiddler 捕获服务器上的流量,并且我想创建一个故障保护,通知我是否有人在关闭 Fiddler 后不小心将其置于此状态.

The reason behind this is that we sometimes turn on the proxy so we can capture traffic on the server with Fiddler, and I want to create a fail-safe that notifies me if someone has accidentally left it in this state after closing Fiddler.

推荐答案

我最终通过配置管理器而不是通过 System.Net.WebProxy 读取值:

I ended up reading the values through the Configuration manager rather than through System.Net.WebProxy:

var proxy = System.Web.Configuration.WebConfigurationManager.GetSection("system.net/defaultProxy") as System.Net.Configuration.DefaultProxySection  
if (proxy != null) { /* Check Values Here */ }

DefalutProxySection 类具有满足我需要的Enabled"和Proxy.ProxyAddress"属性.

The DefalutProxySection class has properties for "Enabled" and "Proxy.ProxyAddress" that met my needs.

这篇关于如何从 web.config 中的 system.net 部分读取 defaultProxy 设置的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆