Asp.net Configuration

Configuration based programming is always preferred instead of writing a program directly. Dotnet itself is build based on configuration (CLR).

For asp.net development we are provided with good configuration support so that we can develop applications with good standards. asp.net provides two configuration files.
  1. Machine.config

  2. Web.config
Both these files are referred when running as asp.net program. these files are xml formatted and they can be modify with any simple text editor. they are automatically loaded in memory for better performance. all these configuration files are process in hierarchical manner which means every configuration files will inherit the settings of parent configuration files. this is also called as configuration inheritance in .net.

Machine config is located in .net framework folder and it is available to all applications running under the current .net framework. it is also called as “Per server basis files”. which means only one machine config is allowed.

Web config is created within the project and it is called as “Application configuration files”. we can create multiple web config files in a single project. for every folder of our application we can create one web config file. In order to create different settings for different folder of our project, we create multiple web config files. by default settings in web config are in simple text and security is required then we can encrypt one or more section of this configuration files using a command line utility called ASPNET_REGIIS.

As it is xml formatted we stand with a root tag called configuration followed by section and settings.
  1. <Configuration>    
  2.         
  3.    <section>    
  4.       
  5.    <Subsection>    
  6.   
  7.    </Subsection>    
  8.         
  9.   ------------Setting ----------    
  10.        
  11.    </section>    
  12.   
  13.  </Configuration>   

All setting of config file are divided into 3 types.

  1. Application Setting
  2. Security Setting
  3. System Setting

Application Setting

1. <aapSettings> Use: To define application wide static variables in asp.net i.e in web app this setting is most recommended. we must not create static variable in our websites as they effect the performance of applications. this setting is directly return under configuration tag.

  1. <configuration>  
  2.   
  3.      <appSettings>  
  4.   
  5.      <add key="Title" value="Online shopping" />  
  6.   
  7.      </appSettings>  
  8.   
  9.  </configuration>  
System.configuration.dll is an assembly which contains a namespace called System.ConfigurationManager. we use this name space to read configuration setting in our program. 

ConfigurationManager.appSetting[“Title”]

2. <connectionStrings> Use: All datasource control and concepts like linq to sql , EDMX use connection string to define there application . it is also return under configuration root tag.

  1. <connectionStrings>  
  2.      
  3.     <add name =”sqlconn” connectionString=”” />  
  4.     
  5. </connectionStrings>  

Once connection string is define we an define in web config we can retrieve individual configuration related to connection string or the entire connection string using configuration manager class.

ConfigurationManager.ConnectionString[“sqlconn”].ConnectionString

3. <Compailation> Use: Using this tag we can specify the project debugging options like whether the project should be compiled with debug support or not, which language to use for dynamic compilation should use. attributes of this tag.

1. debug =True/False (by default is true) : this is most important attribute for every asp.net application during development to get debugging support like breakpoint, debug windows we have to set this to true.once application is completed then we have to set it’s default value false so that our project will be executed faster without any debugging code attached to it.

2. default Language : default language for asp.net is vb.net and when we want to change our page language or for entire project language we can use attribute at page level and default language attribute in compilation tag at Application level.

4. <Trace> : this tag also belong to debugging and this tag can be used during and after development also. trace tag will provide all the run time information which asp.net followed to execute the page.. one of the important asp.net concept is page life cycle. we can see page life cycle execution in trace output. by default trace is not enabled to enable it at application level we have to write :

<trace enabled=”true” pageoutput=”true”/>

“Pageoutput = true” means trace result is displayed directly in this page.if set to false then we have to use trace utility called “trace.axd“ as per of url to see trace result separately.

I hope you will understand configuration concept on asp.net

Ebook Download
View all
Learn
View all