<system.Net>元素(网络设置)配置元素包含应用程序的网络配置信息。
<system.Net>使用元素(网络设置)元素,可以设置代理服务器、设置连接管理参数,并在应用程序中包括自定义身份验证和请求模块。
该 <defaultProxy> 元素 定义类返回的 GlobalProxySelection 代理服务器。 任何未将自己的HttpWebRequest属性设置为特定值的Proxy都使用默认代理。 除了设置代理地址之外,还可以创建不会使用该代理的服务器地址列表,并且可以指示代理不应用于本地地址。
请务必注意,系统的 Internet 设置与配置设置相结合,后者优先。
以下示例将默认代理服务器地址设置为 http://proxyserver,指示不应将代理用于本地地址,并指定对位于 contoso.com 域中的服务器的所有请求都应绕过代理。
<configuration>
<system.net>
<defaultProxy>
<proxy
usesystemdefault = "false"
proxyaddress = "http://proxyserver:80"
bypassonlocal = "true"
/>
<bypasslist>
<add address="http://[a-z]+\.contoso\.com/" />
</bypasslist>
</defaultProxy>
</system.net>
</configuration>
www.contoso.com两个持久连接、与 IP 地址为 192.168.1.2 的服务器建立四个持久连接,以及一个与所有其他服务器的持久连接。
<configuration>
<system.net>
<connectionManagement>
<add address="http://www.contoso.com" maxconnection="2" />
<add address="192.168.1.2" maxconnection="4" />
<add address="*" maxconnection="1" />
</connectionManagement>
</system.net>
</configuration>
使用
以下示例配置自定义身份验证模块。
<configuration>
<system.net>
<authenticationModules>
<add type="MyAuthModule, MyAuthModule.dll" />
</authenticationModules>
</system.net>
</configuration>
可以使用 <webRequestModules> 元素(网络设置) 元素将应用程序配置为使用自定义协议特定的模块从 Internet 资源请求信息。 指定的模块必须实现 IWebRequestCreate 接口。 可以通过在配置文件中指定自定义模块来替代默认 HTTP、HTTPS 和文件请求模块,如以下示例所示。
<configuration>
<system.net>
<webRequestModules>
<add
prefix="HTTP"
type = "MyHttpRequest.dll, MyHttpRequestCreator"
/>
</webRequestModules>
</system.net>
</configuration>