AppSettings vs applicationSettings. is appSettings out of date?

I have a few questions about two ways to save settings in web.config.

AppSettings : Look in web.config

<appSettings> <add key="key1" value="value1"/> <add key="key2" value="value2"/> </appSettings> 

Code Usage :

 ConfigurationManager.AppSettings["key1"]; 

ApplicationSettings / Properties (auto-generated using the "properties" tab in the project)
Take a look at web.config

 <applicationSettings> <Projectname.Properties.Settings> <setting name="TestEnvironment" serializeAs="String"> <value>True</value> </setting> </Projectname.Properties.Settings> </applicationSettings> 

Code Usage :

 Properties.Settings.Default.TestEnvironment 

So what is the difference between these two options for storing settings in web.config?
As far as I can see, the disadvantage of appSettings is that you changed the web.config file yourself, and the application settings were not printed strictly, where as the application parameters.

Both can be replaced as part of a web deployment project.

As far as I know, not used for appSettings . Am I missing something? What is historically older?

+50
c # properties web-deployment-project
Feb 28 '10 at 11:30
source share
4 answers

This was stated above: Pros and cons of appSettings vs applicationSettings (.NET app.config) .

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

Advantage? When I edit a value or add a value on the server where the <applicationSettings > notepad is the best tool, it’s very detailed, and sometimes I just want a line , Maybe a dumb example, but when I adjust the configuration settings between levels to correctly configure automatic deployment, it is extremely useful that it is simple.

I have to agree with marc_s from another discussion, although if you are doing something really complicated, you are probably getting close to having your own configuration section. Since you run serialization into your type of configuration at startup ... you get the same type of validation in this way, just one thing directly depends on the XML serializer.

It also has the advantage that I make Config.LDAPServer or perhaps one configuration for different areas, for example Security.Config and Themes.Config (guessing here!), You can get a really useful / understandable naming scheme where there is a side effect .

+22
Feb 28 '10 at 12:02
source share

ApplicationSettings have a namespace, so two different assemblies can have a timeout parameter without conflicts, and ApplicationSettings are optional, because the default value is set using the attribute in the setting in the code.

+21
Oct 26 '11 at 5:40
source share

One thing I noticed is that AppSettings values ​​can be referenced using <%$ AppSettings: name %> inline tags on aspx pages, but there seems to be no equivalent way to access ApplicationSettings values ​​through inline tags.

+6
Oct 26 '11 at 5:35
source share

I would like to add that the IIS 8.0 GUI (and previous versions) cannot edit the <applicationSettings> section (it is invisible, i.e. it looks as if the settings cannot be configured), while <appSettings> edited with using IIS 8.0.

It would be nice if VS2012 / IIS 8.0 fully used the same GUI configuration system, but the products did not seem to be synchronized in this aspect. One way or another, you may need to edit the application settings using notepad.

Connection strings are displayed in both GUIs, but when using <applicationSettings> in IIS, they include the full path ( Namespace .Properties.Settings. ConnectionStringName ).

+3
Aug 07 '13 at 13:37
source share



All Articles