65.9K
CodeProject 正在变化。 阅读更多。
Home

如何编辑配置文件 Web.Config

starIconstarIconstarIconstarIconstarIcon

5.00/5 (1投票)

2013 年 10 月 11 日

CPOL
viewsIcon

6577

在 web.config 中,我们使用 section 来添加键,如下所示:      <add key="email"

如何编辑配置文件 Web.Config

在 web.config 中,我们使用 <appSettings> section 来添加键,如下所示

  <appSettings>

    <add key="email" value="" />

   <add key="color" value="green" />

  </appSettings>

在代码后台编写以下代码,以便访问键并获取值

 Configuration conf = WebConfigurationManager.OpenWebConfiguration("~");

        AppSettingsSection app = (AppSettingsSection)conf.GetSection("appSettings");

        app.Settings["email"].Value = TextBox1.Text;

        app.Settings.Add("color", "green");

        conf.Save();

希望这有帮助 

© . All rights reserved.