<proxy> 元素(网络设置)

定义代理服务器。

<configuration>
  <system.net>
    <defaultProxy>
      <proxy>

Syntax

<proxy
  autoDetect="True|False|Unspecified"
  bypassonlocal="True|False|Unspecified"
  proxyaddress="uriString"
  scriptLocation="uriString"
  usesystemdefault="True|False|Unspecified"
/>

特性和元素

下列各节描述了特性、子元素和父元素。

特性

属性 说明
autoDetect 指定是否自动检测到代理。 默认值为 Unspecified
bypassonlocal 指定是否为本地资源绕过代理。 本地资源包括本地服务器(http://localhosthttp://loopbackhttp://127.0.0.1)和没有句点的 URI(http://webserver)。 默认值为 Unspecified
proxyaddress 指定要使用的代理 URI。
scriptLocation 指定配置脚本的位置。 不要将 bypassonlocal 特性与此属性一起使用。
usesystemdefault 指定是否使用系统代理设置。 如果设置为/>,后续属性将替代系统代理设置。 默认值为 Unspecified

子元素

没有。

父元素

元素 说明
defaultProxy 配置超文本传输协议 (HTTP) 代理服务器。

文本值

注解

proxy 元素定义应用程序的代理服务器。 如果配置文件中缺少此元素,则 .NET Framework 将使用系统代理设置。

属性的值 proxyaddress 应该是格式正确的统一资源指示器(URI)。

scriptLocation 属性是指自动检测代理配置脚本。 当为 Internet 属性中的连接选择WebProxy”选项时,该类将尝试查找配置脚本(通常命名为Wpad.dat)。 如果 bypassonlocal 设置为任何值, scriptLocation 则忽略。

如果 proxyaddress 属性指定了无效的默认代理,则会引发异常。 InnerException异常的属性应提供有关错误的根本原因的详细信息。

配置文件

此元素可用于应用程序配置文件或计算机配置文件(Machine.config)。

Example

以下示例使用系统代理中的默认值,指定代理地址,并绕过代理进行本地访问。

<configuration>
  <system.net>
    <defaultProxy>
      <proxy
        usesystemdefault="True"
        proxyaddress="http://192.168.1.10:3128"
        bypassonlocal="True"
      />
    </defaultProxy>
  </system.net>
</configuration>

另请参阅