Friday, 22 June 2012

2 ASP.NET Configurations



2  ASP.NET Configurations

·        2.1   How to Asp.Net configurations
·        2.2   How to Machine.Config
·        2.3   How to Web.Config
·        2.4   Elements in a web.config File
2.1  How to Asp.Net configurations
After an ASP.NET application is finished, it needs to be configured on an application Web Server for launching it as a Web site on the network system. The configuration information for the ASP.NET applications is stored XML based configuration files, so they are readable and can be edited in any XML editor or in Visual Studio .NET directly.
In ASP.NET, configuration information is stored in one of two files: machine.config or web.config. The main difference between these two files is that the machine.config file is applied system level configuration while the web.config is implemented to each application based on the inheritance rules.

2.2  How to Machine.Config
In ASP.NET, configuration information is stored in one of two files: machine.config or web.config. Machine.config file is using as root configuration file and provides ASP.NET configuration settings for every application in the Web server. Machine.config configuration file comes with the Microsoft .NET Framework and contains the default settings. While an application can have as many web.config files as it has directories and subdirectories , there is only one machine.config file per machine.
The Machine.config file is located in the folder %windir%\Microsoft.NET\Framework\%version%\config, where %version% is a folder that is named for the current installed version of the .NET Framework. Machine.config file contains the default configuration information for every web application, as well as other application types, on the machine. The machine.config file is processed first and any values specified within the machine .config file are inherited throughout every ASP.NET application on your Web server.
2.3  How to Web.Config
The web.config file is a text file which contains XML elements that affect the behavior of an application. It is efficient to store application-level configuration settings in XML-based files that are cached at runtime. Every ASP.NET application contains its own Web.config file , which resides in the root of the application.
The Web.config file overrides many of the settings in Machine.config, within the scope of the specific ASP.NET application where the Web.config file resides. The default Web.config file created by Visual Studio contains comments specific to the most commonly used settings. These comments provide guidance for using the available parameters for a given configuration element . ASP.NET enables you to manage the entire security configuration from the Web.config file.
2.4  Elements in a web.config File
The web.config file is a text file which contains XML elements that affect the behavior of an application. The following are some of the mportant tags in a web.config file.
<configuration> :    In a Web.config file, all the configuration information for an ASP.NET application must reside between the      <configuration> and </configuration> tags. This is the root node, which contains         the declaration of all other             sections of the Web.config file.
<appSettings>  :       This section of the Web.config file provides a way to define custom application settings for an application. The section    can have multiple <add> subelements.   
<appSettings> <add key="connectionstring" value="localhost;uid=readonly;pwd=user"/>             </appSettings>
<compilation> : This element sets several compilation settings for the  application. Some of the settings involve setting a default  language and debug option for the application setting. Debug pages are larger and execute more slowly, so you should use them  only for testing purposes. This section also provides support for the <compilers>, <assemblies> , and <namespaces> subelements. <namespaces>  :            This subelement is used to add or remove namespace references for             assemblies that must be made available when compiling Web pages.
<authentication> :  The <authentication> element sets the authentication policy for  the application. Possible modes are "Windows," "Forms,"  "Passport," and "None."
 <pages> : The <pages> element allows configuration of page  application specific settings.  
<customErrors> : The <customErrors> element provides a means for defining custom    error messages for an ASP.NET application. This is generally used to point users to a friendlier message than the default error messages. The <customErrors> element section supports multiple <error> subelements that are used to define custom errors.     

No comments:

Post a Comment