What does web.config do in ASP.NET?
Posted: (EET/GMT+2)
If you are just learning about ASP.NET, the web.config file is used to configure application settings for a web application.
The file is stored in the application root directory. For example:
C:\InetPub\wwwroot\MyApplication\web.config
ASP.NET reads the configuration automatically when requests are processed.
A simple example what the file might contain:
<configuration>
<system.web>
<compilation debug="true" />
<customErrors mode="Off" />
</system.web>
</configuration>
This enables debugging and disables custom error pages. Note that there is also built-in safety: if you attempt to request the web.config file directly with your browser (as in http://mysite/myapp/web.config) the request is denied.
You can also configure authentication, session state, and application settings from the same file. Furthermore, changes to web.config are detected automatically by ASP.NET, and the application is restarted when the file changes.