如何编辑配置文件 Web.Config





5.00/5 (1投票)
在 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();
希望这有帮助