What is AppSetting section in Web.Config file?
- The <appSettings> element of a web.config file where connection strings, server names, file paths, and other miscellaneous settings are stored.
- The items inside appSettings need to be configurable depending upon the environment.
- Web.config file defines configuration for a web project.
- AppSetting section is used to set the user defined values. For example: The ConnectionString which is used throughout the project for database connection.
- AppSetting section in the configuration file is a section that allows us to keep configurable and application wide settings (for example: ConnectionString) that an application requires in order to perform the tasks properly.
- This helps in easy maintenance and deployment of the application.Syntax:
<add key="ConnectionString" value="(your connection string)" />
string strConnection = ConfigurationSettings.AppSettings["ConnectionString"];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.Example:
<add key="Application Name" value="MyApplication" />
- It contains custom application settings.
- This is a predefined configuration section provided by the .NET framework.