WebConfigurationManager.GetSection 方法

定义

从当前应用程序的默认配置文件中检索指定的配置节。

重载

GetSection(String)

从当前应用程序的配置文件中检索指定的配置节。

GetSection(HttpContext, String)

从与指定上下文相关的应用程序配置文件中检索指定的配置节。

GetSection(String, String, String)

使用网站名称、虚拟路径和节路径检索指定的配置节。

GetSection(HttpContext, String, Type)

使用与指定上下文相关的应用程序配置文件中的指定配置节类型检索指定的配置节。

GetSection(String, String, String, Type)

使用网站名称、虚拟路径、节路径和运行时类型检索指定的配置节。

GetSection(String)

从当前应用程序的配置文件中检索指定的配置节。

public:
 static Microsoft::Web::Administration::ConfigurationSection ^ GetSection(System::String ^ sectionPath);
public static Microsoft.Web.Administration.ConfigurationSection GetSection (string sectionPath);
static member GetSection : string -> Microsoft.Web.Administration.ConfigurationSection
Public Shared Function GetSection (sectionPath As String) As ConfigurationSection

参数

sectionPath
String

配置节名称。

返回

指定的配置节对象或 null(如果该节不存在)。

例外

无法加载有效的配置文件。

注解

GetSection(String)如果从 Web 应用程序中调用重载,它将从系统根据 Web 应用程序的配置层次结构选择的配置文件中返回 节。

注意

如果应用程序使用 HTTP 以外的协议,则需要使用 GetSection(HttpContext, String)GetSection(String, String, String, Type) 重载,每个重载都采用节名称和 System.Web.HttpContext 参数列表中的对象。 必须指定 , HttpContext 使系统能够返回特定配置层次结构级别的配置设置。 但是,如果指定的配置路径在当前应用程序之外, GetSection 则 和 GetSection(String, String, String, Type) 将返回当前正在运行的应用程序的应用程序级配置设置。 如果使用 GetSection(String),它仅采用节名称,系统将始终尝试在应用程序级别返回配置设置。

重要

使用 GetSection(String) 作为运行时操作受到安全限制的限制。 例如,可能无法在运行时访问或修改节。

适用于

GetSection(HttpContext, String)

从与指定上下文相关的应用程序配置文件中检索指定的配置节。

public:
 static Microsoft::Web::Administration::ConfigurationSection ^ GetSection(System::Web::HttpContext ^ context, System::String ^ sectionPath);
public static Microsoft.Web.Administration.ConfigurationSection GetSection (System.Web.HttpContext context, string sectionPath);
static member GetSection : System.Web.HttpContext * string -> Microsoft.Web.Administration.ConfigurationSection
Public Shared Function GetSection (context As HttpContext, sectionPath As String) As ConfigurationSection

参数

context
HttpContext

当前请求的 HttpContext

sectionPath
String

配置节名称。

返回

指定的配置节对象或 null(如果该节不存在)。

例外

无法加载有效的配置文件。

注解

GetSection(HttpContext, String)如果从 Web 应用程序内调用重载,它将从系统根据 System.Web.HttpContext Web 应用程序的 对象选择的配置文件中返回 节。

注意

如果应用程序使用 HTTP 以外的协议,则需要使用 GetSection(HttpContext, String)GetSection(String, String, String, Type) 重载,每个重载都采用节名称和 HttpContext 参数列表中的 。 必须指定 , HttpContext 使系统能够返回特定配置层次结构级别的配置设置。 但是,如果指定的配置路径在当前应用程序之外, GetSection(HttpContext, String) 则 和 GetSection(String, String, String, Type) 将返回当前正在运行的应用程序的应用程序级配置设置。 如果使用 GetSection(String) 仅采用节名称的重载,系统将始终尝试在应用程序级别返回配置设置。

重要

使用 GetSection(HttpContext, String) 作为运行时操作受到安全限制的限制。 例如,可能无法在运行时访问或修改节。

适用于

GetSection(String, String, String)

使用网站名称、虚拟路径和节路径检索指定的配置节。

public:
 static Microsoft::Web::Administration::ConfigurationSection ^ GetSection(System::String ^ siteName, System::String ^ virtualPath, System::String ^ sectionPath);
public static Microsoft.Web.Administration.ConfigurationSection GetSection (string siteName, string virtualPath, string sectionPath);
static member GetSection : string * string * string -> Microsoft.Web.Administration.ConfigurationSection
Public Shared Function GetSection (siteName As String, virtualPath As String, sectionPath As String) As ConfigurationSection

参数

siteName
String

网站的名称。

virtualPath
String

Web.config文件的虚拟路径。

sectionPath
String

配置节名称。

返回

ConfigurationSection 对象。

例外

无法加载有效的配置文件。

传递给方法的参数之一是 null

注解

GetSection(String, String, String) 载返回一个 ConfigurationSection 对象,该对象表示所请求位置的配置。 此方法首先在 参数中 siteName 查找请求的网站,然后在指定的 virtualPath中查找Web.config文件。 GetSection(String, String, String) 然后,在Web.config 文件中搜索请求的配置 sectionPath

重要 使用 GetSection(String, String, String) 作为运行时操作受到安全限制的限制。 例如,可能无法在运行时访问或修改节

适用于

GetSection(HttpContext, String, Type)

使用与指定上下文相关的应用程序配置文件中的指定配置节类型检索指定的配置节。

public:
 static Microsoft::Web::Administration::ConfigurationSection ^ GetSection(System::Web::HttpContext ^ context, System::String ^ sectionPath, Type ^ sectionType);
public static Microsoft.Web.Administration.ConfigurationSection GetSection (System.Web.HttpContext context, string sectionPath, Type sectionType);
static member GetSection : System.Web.HttpContext * string * Type -> Microsoft.Web.Administration.ConfigurationSection
Public Shared Function GetSection (context As HttpContext, sectionPath As String, sectionType As Type) As ConfigurationSection

参数

context
HttpContext

当前 HttpContext 请求的 对象。

sectionPath
String

配置节名称。

sectionType
Type

配置节类型

返回

指定的配置节对象或 null(如果该节不存在)。

例外

无法加载有效的配置文件。

传递给方法的参数之一是 null

参数的值 sectionType 不派生自 类, ConfigurationSection 也不提供公共构造函数。

注解

GetSection(HttpContext, String, Type)如果从 Web 应用程序内调用重载,它将从系统根据 System.Web.HttpContext Web 应用程序的对象以及sectionPath提供的 和 sectionType 参数选择的配置文件中返回 节。

注意

如果应用程序使用 HTTP 以外的协议,则需要使用 GetSection(HttpContext, String)GetSection(String, String, String, Type) 重载,每个重载都采用节名称和 HttpContext 参数列表中的 。 必须指定 , HttpContext 使系统能够返回特定配置层次结构级别的配置设置。 但是,如果指定的配置路径在当前应用程序之外, GetSection(HttpContext, String) 则 和 GetSection(String, String, String, Type) 将返回当前正在运行的应用程序的应用程序级配置设置。 如果使用 GetSection(String) 仅采用节名称的重载,系统将始终尝试在应用程序级别返回配置设置。

重要

使用 GetSection(HttpContext, String, Type) 作为运行时操作受到安全限制的限制。 例如,可能无法在运行时访问或修改节。

适用于

GetSection(String, String, String, Type)

使用网站名称、虚拟路径、节路径和运行时类型检索指定的配置节。

public:
 static Microsoft::Web::Administration::ConfigurationSection ^ GetSection(System::String ^ siteName, System::String ^ virtualPath, System::String ^ sectionPath, Type ^ sectionType);
public static Microsoft.Web.Administration.ConfigurationSection GetSection (string siteName, string virtualPath, string sectionPath, Type sectionType);
static member GetSection : string * string * string * Type -> Microsoft.Web.Administration.ConfigurationSection
Public Shared Function GetSection (siteName As String, virtualPath As String, sectionPath As String, sectionType As Type) As ConfigurationSection

参数

siteName
String

网站的名称。

virtualPath
String

Web.config文件的虚拟路径。

sectionPath
String

配置节名称。

sectionType
Type

配置节的运行时类型。

返回

ConfigurationSection 对象。

注解

GetSection(String, String, String, Type) 载返回一个 ConfigurationSection 对象,该对象表示所请求位置的配置。 此方法首先在 参数中 siteName 查找请求的网站,然后在指定的 virtualPath中查找Web.config文件。 GetSection(String, String, String, Type)然后,在 Web.config 文件中搜索与 参数中sectionType提供的运行时类型匹配的请求配置sectionPath

重要

使用 GetSection(String, String, String, Type) 作为运行时操作受到安全限制的限制。 例如,可能无法在运行时访问或修改节。

适用于