appSettings 与 applicationSettings.appSettings 过时了? [英] appSettings vs applicationSettings. appSettings outdated?

查看:18
本文介绍了appSettings 与 applicationSettings.appSettings 过时了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于在 web.config 中保存设置的两种方法,我有一些问题.

I've got some questions about two ways to save settings in the web.config.

应用设置:在 web.config 中查看

Appsettings: Look in 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 是.

So, what's the difference between these two storage possibilities of settings in the web.config?
As far as I can see, a downside of the appSettings is that you have modify the web.config yourself and the appSettings are not strong typed, where as the applicationSettings are.

两者都可以在 Web 部署项目中替换.

Both are replaceable within a web deployment project.

就我而言,appSettings 没有用.我在这里错过了什么吗?哪个是历史上看到的更旧的?

As far as I am concerned, there is no use for appSettings. Am I missing something here? Which is the historically seen older one?

推荐答案

这之前已经在这里讨论过:appSettings 与 applicationSettings (.NET app.config) 的优缺点.

This has been discussed before here: Pros and cons of appSettings vs applicationSettings (.NET app.config).

至于你的问题:较旧的是>,大约在2.0之前,>在2.0中可用.

As for your questions: The older one is <appSettings>, it was around before 2.0, <applicationSettings> became available in 2.0.

优势?当我编辑一个值,或在最好的工具是记事本的服务器上添加一个值时,> 非常 冗长,有时我只是想要一个字符串.也许是一个愚蠢的例子,但是当我调整层之间的配置设置以正确设置自动部署时,它的简单性非常有用.

Advantage? When I'm editing a value, or adding a value on a server where the best tool is notepad <applicationSettings> is very verbose, and sometimes I just want a string. Maybe a dumb example, but when I'm tweaking the config settings between tiers to get the automatic deployment setup correctly, it's tremendously useful that it's simple.

我必须同意其他讨论中的 marc_s,如果您正在做任何非常复杂的事情,您可能已经接近应该拥有自己的配置部分的地步.由于您在启动时反序列化为您的配置类型……您可以通过这种方式进行相同的类型检查,唯一的区别是直接通过 XML 序列化程序.

I have to agree with marc_s from the other discussion though, if you're doing anything that's really complex, you're probably approaching the point you should have your own configuration section anyway. Since you're de-serializing into your config type on startup...you get the same type checking that way, just via the XML Serializer directly is the only difference.

这也有我做 Config.LDAPServer 的优势,或者可能是针对不同领域的一个配置,比如 Security.ConfigThemes.Config(在这里猜测!),您可以在其中获得一个非常有用/清晰的命名方案作为附带好处.

This also has the advantage of me doing Config.LDAPServer or maybe one config for different areas each, like Security.Config and Themes.Config (guessing here!), you can get a really useful/clear naming scheme in there as a side benefit.

这篇关于appSettings 与 applicationSettings.appSettings 过时了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆