What is AppSettings for?

I was taking a look at the Web.confg and would like to know what the <appSettings> is for? What does it interfere with our application?

Author: LINQ, 2019-02-07

3 answers

Contains custom application settings. This is a predefined configuration section provided by the .NET Framework.

Syntax

<appSettings>
  <!-- Elements to add, clear, or remove configuration settings -->
</appSettings>

Comments

The element stores custom application configuration information, such as database connection strings, file paths, XML Web Service URLs, or any other custom configuration information for an application. The key/value pairs specified in the element are accessed in code using the ConfigurationSettings class.

You can use the attribute file in the web element. config and application configuration files. This attribute specifies a configuration file that provides additional settings or overrides the settings specified in the element. The attribute file can be used in source code control team development scenarios, such as when a user wants to override the specified project settings in an application configuration file. Configuration files specified by the attribute file must have a root node instead .

Example

The following example shows an external application settings file (custom.config) that defines a custom application configuration:

<?xml version="1.0" encoding="utf-8" ?>
<appSettings>
  <add key="MyCustomSetting" value="MyCustomSettingValue" />
</appSettings>

The following example shows an application configuration file that consumes the configuration in the external settings file and defines its own configuration of application:

<configuration>
  <appSettings file="custom.config">
    <add key="ApplicationName" value="MyApplication" />
  </appSettings>
</configuration>

Configuration file

This element can be used in the application configuration file, machine configuration file (Machine. config), and Web. config files that are not at the application directory level.

Documentation

 5
Author: Wictor Chaves, 2019-02-07 13:17:16

The <appSettings/> tag serves as a container for the specific settings of your application, in this case, the settings that the developer wants to store.

Example:

<appSettings>
  <add key="conf1" value="teste"/>
<appSettings/>

Note that we add in the tag <appSettings/> a child tag, which corresponds to our configuration. The attributes of <add/> used were key and value, where key defines the name of the configuration and value the value it stores.

Source: http://www.linhadecodigo.com.br/artigo/1612/net-entendendo-o-arquivo-webconfig.aspx#ixzz5eqkibPuq

 4
Author: Albertt Santos, 2019-02-07 13:04:35

In appSettings we can create keys and set values for these keys and, which I think is very good, we don't need to recompile the application to exchange the value of these keys.

Let's go to two examples of where to use appSettings:

1-let's assume that right after the homologation of the project, your client, decided to exchange the email in which he receives when the application sends. Instead of going to look for the variable that we save his email and exchange for the new one, in appSettings we exchange to the new e-mail and ready.

2 - " - What a nice John, look at this condition, if item = = 45. Why 45???". Of course we will not put everything in appSettings, but it would be much better to understand if the condition was, If item == appSettings["codcar"]. A basic example!

Is explained... Now get to work!

Let's go on our Web.Config create our keys. It is extremely simple:

Example: http://www.morcegosweb.com/morcegos/arquivos/lightbox/app1.jpg

Read More Here for you to understand better: http://www.linhadecodigo.com.br/artigo/2209/definicoes-da-aplicacao-appsettings.aspx#ixzz5eqlRvG48

 4
Author: Marcos Vinicius Leão, 2019-02-07 13:04:48