Monday, December 27, 2010

ASP.NET Configuration System

ASP.NET Configuration System
ASP.NET Configuration system is used to describe the properties and behaviors of various aspects of ASP.NET applications.
Unlike Classic ASP where configuration information was stored in a binary repository called the IIS metabase, ASP.NET uses XML-based configuration system that is more accessible and easier to use.

You can configure features, such as Connection Strings, Authentication Modes, Caching, Debug and Tracing, Custom Errors and many more.
Benefits of XML-based Configuration files
o ASP.NET Configuration system is extensible and application specific information can be stored and retrieved easily. It is human readable.
o You need not restart the web server when the settings are changed in configuration file. ASP.NET automatically detects the changes and applies them to the running ASP.NET application.
o You can edit Configuration file using simple text editor. It can be easily exchanged between servers in a typical web farm scenario.
Configuration Files
ASP.NET configuration data is stored in two primary XML-based files. These files allow you to easily edit configuration data at any moment even after the application is deployed on server.
Different types of Configuration files
Machine.config: Server or machine-wide configuration file
Web.config: Application configuration files which deal with a single application
Server Configuration file (Machine.config)
Every ASP.NET server installation includes a configuration file named machine.config, and this file is installed as a part of .NET Framework installation. You can find machine.config in C:\\Microsoft.NET\Framework\\Config\
ASP.NET 2.0 provides another two files machine.config.default and machine.config.comments. The machine.config.default acts as a backup for the machine.config file. The machine.config.comments file contains a description for each configuration section and explicit settings for the most commonly used values.
Application Configuration file (Web.config)
Each and Every ASP.NET application has its own copy of configuration settings stored in a file called Web.config. If the web application spans multiple folders, each sub folder has its own Web.config file that inherits or overrides the parent's file settings.


Tracing in ASP.Net




 While developing a web application, developers came across with many kinds of errors, e.g. an error occurs while running an application because of an instance of an object is not set properly.
 In Microsoft .Net Framework we find a “Debugging and Tracing” feature for sorting and fixing these kinds of errors.

 Debugging feature allow developers to step into their code, set break points, have watch windows to observe the values or variables etc.

 In classic ASP, method used to display an error message is Response.Write. It provides lot of facility to the developers; it is quick, easy to use etc. but it has downsides as well.

.

 To overcome these kinds of situations ASP.Net provides a Tracing feature. This feature provides a refined way for outputting page-level information.

It uses two methods Trace.Write and Trace.Warn:



'Displays simple message (In Black Text)
Trace.Write("Your Message") 'The trace message to write to the log

'Displays an error message (In Red)
Trace.Warn("Your Message") 'The trace message to write to the log
 . But before using this feature of ASP.Net you have to enable it either on the page level or web application level.

You can enable tracing on page level using:

<%@ Page Trace=[True|False]%>
The advantage in using page level tracing is, you don’t need to remove Trace.Write and Trace.Warn from your page the only thing to do is set:
<%@ Page Trace=False%>
On Application level tracing you need to modify setting in the Web.Config file:


Note: The default value for enable attribute is set equal to false.

The description for trace attribute is as follows:

• Enable (True/False): Turns application level tracing on/off.
• requestLimit (length in integer): This the limit for HTTP requests for which tracing information will be stored. This allows you to collect batch of information from multiple requests. When the maximum is reached, the information for the oldest request is abandoned every time a new request is received.
• pageOutput (True/False): Determine whether the tracing information will be displayed on the page.
• traceMode (SortByTime/SortByCategory): Determines the sort order of trace messages.
• localOnly (True/False): Determines whether to show message to the local clients (unlived site running on your computer) only, or to remote clients (live site users).

Note: The settings in the Web.config file specify the default behavior; i.e., what an application should do when no page-level directive for tracing is specified. You can override these settings on a page-level by explicitly setting the Trace page-directive to True/False.

No comments:

Post a Comment