In this post, I will explain about Asp.Net Web Configuration File (Web.Config).
Web.Config is the main settings and configuration file used for an Asp.Net web application. Web.Config file is used to manage various settings that define a website. The settings are stored in XML files that are separate from your application code. In this way, you can configure settings independently from your code. Asp.Net web application contains a single Web.Config file in the root directory. An application can have more than one web.config file in a different directory. Asp.Net Configuration file is used to describe the properties and behaviours of Asp.Net applications. It is an XML document.
Web.Config is the main settings and configuration file used for an Asp.Net web application. Web.Config file is used to manage various settings that define a website. The settings are stored in XML files that are separate from your application code. In this way, you can configure settings independently from your code. Asp.Net web application contains a single Web.Config file in the root directory. An application can have more than one web.config file in a different directory. Asp.Net Configuration file is used to describe the properties and behaviours of Asp.Net applications. It is an XML document.
Benefits of XML-based Configuration files
- Asp.Net Web.Config file is extensible and application-specific information can be stored and retrieved easily. It is human readable.
- No need to restart web server when settings are changed in a configuration file. Asp.Net automatically detects the changes and applies them to the running Asp.Net application.
- Any standard text editor or XML parser can be used to create and edit Asp.Net configuration files.
What web.config file contains?
There is a number of important settings that can be stored in the Web.Config file. Some of the most frequently used configurations inside Web.Config file is:
- Database connections
- Caching settings
- Session States
- Error Handling
- Security
Example of web.config file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation defaultLanguage="c#" debug="true" />
<customErrors mode="RemoteOnly" />
<authentication mode="Windows" />
<authorization>
<allow users="*" />
</authorization>
<trace enabled="false" requestLimit="10" pageOutput="false"
traceMode="SortByTime" localOnly="true" />
<sessionState mode="InProc" cookieless="false" timeout="20" />
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
</system.web>
</configuration>
<configuration>
<system.web>
<compilation defaultLanguage="c#" debug="true" />
<customErrors mode="RemoteOnly" />
<authentication mode="Windows" />
<authorization>
<allow users="*" />
</authorization>
<trace enabled="false" requestLimit="10" pageOutput="false"
traceMode="SortByTime" localOnly="true" />
<sessionState mode="InProc" cookieless="false" timeout="20" />
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
</system.web>
</configuration>