<configuration>
<!-- Configuration section declarations. -->
<configSections>
<!-- You do not need to declare the appSettings section. Machine.config ships with a declaration for this section. -->
<section name="appSettings"
type="System.Web.Configuration.NameValueSectionHandler"/>
</configSections>
</configuration>
下面的示例说明如何在使用内置 appSettings 节的配置文件中使用应用程序设置。
<configuration>
<!-- The following code uses the predefined appSettings section. -->
<appSettings>
<add key="Application Name" value="MyApplication" />
</appSettings>
</configuration>
ConfigurationSettings.AppSettings 是特殊属性,它提供指向配置文件的 <appSettings> 节中定义的应用程序设置的快捷方式。下面的示例说明如何检索在前一个配置文件示例中定义的应用程序名。
[Visual Basic]
Public Sub ReadMyAppSettings()
Dim appName As String