ASP.NET - Configuration logo
ASP.NET Basics
ASP.Net Introduction
ASP.NET - Introduction
ASP.NET - Environment Setup
ASP.NET - Basic Controls
ASP.Net Button
ASP.Net RadioButton
ASP.Net Textbox
ASP.Net Label
ASP.NET - Client Side
ASP.NET - Server Side
ASP.NET - Ad Rotator
ASP.Net Hyperlink
ASP.NET - Calendars
ASP.NET - Life Cycle
ASP.NET - Debugging
ASP.Net Session
ASP.Net LinkButton
ASP.Net DropDownList
ASP.NET - Data Binding
ASP.Net Calender
ASP.Net Checkbox
ASP.NET - Multi Threading
ASP.Net Tutorial
ASP.NET - File Uploading
ASP.Net Upload Multiple Files
ASP.Net Cookie
ASP.NET - Quick Guide
ASP.NET - Data Caching
ASP.NET Useful Resources
ASP.NET - Multi Views
ASP.NET - Panel Controls
ASP.NET - Deployment
ASP.Net DataGrid
ASP.Net WebForm User Registration
ASP.NET - Security
ASP.Net Action Filters
ASP.NET - Error Handling
ASP.Net Fileuplaod
ASP.NET - Data Sources
ASP.NET - Validators
ASP.NET - Ajax Control
ASP.NET Tutorial in PDF
ASP.NET - Directives
ASP.Net DataList
ASP.NET - Custom Controls
ASP.NET - Configuration
ASP.Net WebForm Validation Summary
ASP.NET - Server Controls
ASP.NET - Managing State
ASP.NET - Event Handling
Learn ASP.Net Tutorial
ASP.Net Server Controls
ASP.NET - Database Access
ASP.NET - Web Services
ASP.NET - Personalization
ASP.Net Life Cycle
Discuss ASP.NET
ASP.Net Download File
ASP.NET Basics
Previous : ASP.NET - Custom Controls Next : ASP.Net WebForm Validation Summary

ASP.NET - Configuration

The behavior of an ASP.NET application is affected by different settings in the configuration files:

  • machine.config
  • web.config

The machine.config file contains default and the machine-specific value for all supported settings. The machine settings are controlled by the system administrator and applications are generally not given access to this file.

An application however, can override the default values by creating web.config files in its roots folder. The web.config file is a subset of the machine.config file.

If the application contains child directories, it can define a web.config file for each folder. Scope of each configuration file is determined in a hierarchical top-down manner.

Any web.config file can locally extend, restrict, or override any settings defined on the upper level.

Visual Studio generates a default web.config file for each project. An application can execute without a web.config file, however, you cannot debug an application without a web.config file.

The following figure shows the Solution Explorer for the sample example used in the web services tutorial:


In this application, there are two web.config files for two projects i.e., the web service and the web site calling the web service.

The web.config file has the configuration element as the root node. Information inside this element is grouped into two main areas: the configuration section-handler declaration area, and the configuration section settings area.

The following code snippet shows the basic syntax of a configuration file:


   <!-- Configuration section-handler declaration area. -->
         <section name="section1" type="section1Handler" />
         <section name="section2" type="section2Handler" />
   <!-- Configuration section settings area. -->
      <s1Setting1 attribute1="attr1" />
      <s2Setting1 attribute1="attr1" />
      <authentication mode="Windows" />

Configuration Section Handler declarations

The configuration section handlers are contained within the <configSections> tags. Each configuration handler specifies name of a configuration section, contained within the file, which provides some configuration data. It has the following basic syntax:

   <section />
   <sectionGroup />
   <remove />

It has the following elements:

  • Clear - It removes all references to inherited sections and section groups.

  • Remove - It removes a reference to an inherited section and section group.

  • Section - It defines an association between a configuration section handler and a configuration element.

  • Section group - It defines an association between a configuration section handler and a configuration section.

Application Settings

The application settings allow storing application-wide name-value pairs for read-only access. For example, you can define a custom application setting as:

      <add key="Application Name" value="MyApplication" /> 

For example, you can also store the name of a book and its ISBN number:

      <add key="appISBN" value="0-273-68726-3" />
      <add key="appBook" value="Corporate Finance" />

Connection Strings

The connection strings show which database connection strings are available to the website. For example:

   <add name="ASPDotNetStepByStepConnectionString" 
      Data Source=E:\projectsdatacaching /
      providerName="System.Data.OleDb" />
   <add name="booksConnectionString" 
      Data Source=C: databindingApp_Dataooks.mdb"
      providerName="System.Data.OleDb" />

System.Web Element

The system.web element specifies the root element for the ASP.NET configuration section and contains configuration elements that configure ASP.NET Web applications and control how the applications behave.

It holds most of the configuration elements needed to be adjusted in common applications. The basic syntax for the element is as given:


The following table provides brief description of some of common sub elements of the system.web element:


This is required to identify users who are not authenticated when authorization is required.


It configures the authentication support. The basic syntax is as given:

<authentication mode="[Windows|Forms|Passport|None]"> 


It configures the authorization support. The basic syntax is as given:

   <allow .../>
   <deny .../>


It Configures the cache settings. The basic syntax is as given:



It defines custom error messages. The basic syntax is as given:

<customErrors defaultRedirect="url" mode="On|Off|RemoteOnly">
   <error. . ./>


It defines configuration settings used for deployment. The basic syntax is as follows:

<deployment retail="true|false" />


It defines configuration settings for hosting environment. The basic syntax is as follows:

<hostingEnvironment idleTimeout="HH:MM:SS"
   shutdownTimeout="number" urlMetadataSlidingExpiration="HH:MM:SS"


It configures the identity of the application. The basic syntax is as given:

<identity impersonate="true|false" userName="domainusername"
   password="<secure password>"/>


It configures keys to use for encryption and decryption of Forms authentication cookie data.

It also allows configuring a validation key that performs message authentication checks on view-state data and forms authentication tickets. The basic syntax is:

<machineKey validationKey="AutoGenerate,IsolateApps" [String]
   decryptionKey="AutoGenerate,IsolateApps" [String]
   validation="HMACSHA256" [SHA1 | MD5 | 3DES | AES | HMACSHA256 | 
   HMACSHA384 | HMACSHA512 | alg:algorithm_name]
   decryption="Auto" [Auto | DES | 3DES | AES | alg:algorithm_name]


This configures parameters of managing and authenticating user accounts. The basic syntax is:

<membership defaultProvider="provider name"
   userIsOnlineTimeWindow="number of minutes"


It provides page-specific configurations. The basic syntax is:

<pages asyncTimeout="number" autoEventWireup="[True|False]"
      buffer="[True|False]" clientIDMode="[AutoID|Predictable|Static]"
      masterPageFile="file path" 
      pageBaseType="typename, assembly"
      viewStateEncryptionMode="[Always|Auto|Never]" >


It configures user profile parameters. The basic syntax is:

<profile enabled="true|false" inherits="fully qualified type
   automaticSaveEnabled="true|false" defaultProvider="provider


It configures settings for user roles. The basic syntax is:

<roleManager cacheRolesInCookie="true|false" cookieName="name"
   cookiePath="/" cookieProtection="All|Encryption|Validation|None"
   cookieRequireSSL="true|false " cookieSlidingExpiration="true|false
   cookieTimeout="number of minutes"
   defaultProvider="provider name" domain="cookie domain"> 
   maxCachedResults="maximum number of role names cached"


It configures the security policy. The basic syntax is:

   <trustLevel />


It defines mappings to hide the original URL and provide a more user friendly URL. The basic syntax is:

<urlMappings enabled="true|false">
   <clear />


It provides the name of shared location for client scripts. The basic syntax is:

<webControls clientScriptsLocation="String" />


This configures the web services.

Previous : ASP.NET - Custom Controls Next : ASP.Net WebForm Validation Summary
© Copyright 2018 W3Hello Publishing Limited. All rights reserved.
Contact us | Sitemap