【发布时间】:2011-01-21 23:52:42
【问题描述】:
我对在 web.config 中保存设置的两种方法有一些疑问。
应用设置: 在 web.config 中查看
<appSettings>
<add key="key1" value="value1"/>
<add key="key2" value="value2"/>
</appSettings>
在代码隐藏中的使用:
ConfigurationManager.AppSettings["key1"];
ApplicationSettings/Properties(使用项目中的“属性”选项卡自动生成)
查看 web.config
<applicationSettings>
<Projectname.Properties.Settings>
<setting name="TestEnvironment" serializeAs="String">
<value>True</value>
</setting>
</Projectname.Properties.Settings>
</applicationSettings>
在代码隐藏中的使用:
Properties.Settings.Default.TestEnvironment
那么,web.config 中这两种设置的存储可能性有什么区别呢?
据我所知,appSettings 的一个缺点是您自己修改了 web.config,并且 appSettings 不是强类型,而 applicationSettings 是。
两者都可以在 Web 部署项目中替换。
就我而言,appSettings 没有用处。我在这里错过了什么吗?哪个是历史上较旧的?
【问题讨论】:
标签: c# asp.net properties appsettings web-deployment-project