web.config example

Web config is one of the most important file that contain configuration information in any application, here we learn what is web.config file in application and how to use that file!

What is Web.Config in

Web.Config in Application is a human-readable XML file, that you can open and edit with any simple text editor, Web.Config file contain configuration information of application, when you create a application a default Web.Config will be added in root of your application.

Using Web.Config in

Web.Config contain configuration information for a particular Application, but in hierarchy there another file called Web.Config, that contain configuration information of all application on that machine.

\WINNT\Microsoft.NET\Framework\[Framework Version]\CONFIG\machine.config

To make any changes in that file you need to have system level permission.

Now we talk about only Web.Config, while developing application the file will reside in root of your app, and while deploying on IIS, the file will be at the root of virtual directory.


Whenever you make any changes in Web.Config settings the application or the service will be automatically restarted, even a single letter changes will take the effect.

The top tag in web.config is configuration


Here we discuss some of the important tags, which you change very often in your application

web.config appSettings example

You can add any number of key-value pair in this section

<add key="webpages:Version" value="" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="TestKey" value="TestValue"/>

appSettings is the section where you, you can add a new key-value, then retrieve the same in your application using ConfigurationManager.AppSettings

web.config customErrors example

If you want to implement custom error page to display user-friendly messages for any unhandled application error, then you can specify different page for different error code.

<customErrors mode="Off" defaultRedirect="~/error">
<error statusCode="404" redirect="~/error/page404" />
<error statusCode="500" redirect="~/error/page500" />
web.config Custom configuration example

In this section of web.config you can add all Custom configuration details, please read the complete article on how to implement configuration framework in application

<sectionGroup name="CustomSetting">
     <section name="SystemSettings" type="SystemHandler,WebTrainingRoom" />
     <section name="BusinessSettings" type="BusinessHandler, WebTrainingRoom" />

Hope now you got the idea of how to work with web.config in application

Hire Asp.Net Developer Web.config appSettings configuration customErrors examples Interview Questions Answers MVC interview Core question application development tutorials with real-time examples create web application with SQL database step-by-step.
Asp.Net C# Examples | Join Asp.Net Course | Learn MVC | Core Tutorial