Analysis of ASP. NET configuration file format

Source: Internet
Author: User
Tags configuration settings

What is the role of the ASP. NET configuration file? The configuration information of ASP. NET Resources is contained in the configuration file set. The name of each file is Web. config. What is the format of ASP. NET configuration file? Each ASP. NET configuration file contains a nested hierarchy consisting of XML tags and child tags used to specify configuration settings. Because tags must be XML in the standard format, tags, subtags, and attributes must be case sensitive. Both the tag and attribute names are case-sensitive, that is, the first character of the tag name is lower case, and the first letter of any subsequent connection word is all uppercase. The attribute value is in Pascal's case-sensitive format, that is, the first character is capitalized, and the first letter of any subsequent Connected Word is also capitalized. Except true and false, they are always in lower case.

The following describes the specific ASP. NET configuration file format:

All configuration information is located between the <configuration> and </configuration> root XML tag. The configuration information between tags is divided into the configuration section handler declaration area and configuration section setting area.

The configuration section handler declaration appears at the top of the configuration file between the <configSections> and </configSections> labels. Each declaration contained in the <section> tag specifies the section name that provides the specific configuration dataset and the. NET Framework class name that processes the configuration data in this section.

The configuration section setting area is behind the <configSections> area, which contains the actual configuration settings. Each declaration in the <configSections> area has a configuration section. Each configuration section contains a sub-tag with the settings of this section.

The following Web. config file example declares two configuration <section> handlers. One handler manages application settings, and the other manages session status.

 
 
  1. ﹤configuration﹥  
  2.    ﹤configSections﹥  
  3.       ﹤section name="appSettings"     
  4.          type="System.Configuration.NameValueFileSectionHandler,   
  5.          System, Version=1.0.3300.0,   
  6.          Culture=neutral, PublicKeyToken=b77a5c561934e089"/﹥           
  7.       ﹤section name="sessionState"   
  8.          type="System.Web.SessionState.SessionStateSectionHandler,   
  9.          System.Web, Version=1.0.3300.0, Culture=neutral,   
  10.          PublicKeyToken=b03f5f7f11d50a3a"   
  11.          allowDefinition="MachineToApplication"/﹥  
  12.    ﹤/configSections﹥  
  13.    ﹤appSettings﹥  
  14.       ﹤add key="dsn" value="localhost;uid=MyUserName;pwd=;"/﹥  
  15.       ﹤add key="msmqserver" value="server\myqueue"/﹥  
  16.    ﹤/appSettings﹥  
  17.      
  18.    ﹤sessionState cookieless="true" timeout="10"/﹥  
  19. ﹤/configuration﹥ 

You only need to declare the configuration section handler once. It can be placed in the root Machine. config file of the server or in the Web. config file under the virtual directory that contains the Web application file. The configuration file in the subdirectory automatically inherits the configuration handler declared in the parent directory. For more information, see configure inheritance.

Configuration settings are usually nested under the group label. The highest-level section Mark usually indicates the namespace set for the application configuration. For example, the most advanced <system.net> MARK represents the setting of the network class, And the <system. web> MARK represents the setting of the ASP. NET class.

The following example shows tag nesting.

 
 
  1. <Configuration>
  2. <ConfigSections>
  3. <SectionGroup name ="System.net">
  4. <Section name ="AuthenticationModules" 
  5. Type = "System. Net. Configuration. NetAuthenticationModuleHandler,
  6. System, Version = 1.0.3300.0, Culture = neutral,
  7. PublicKeyToken = b77a5c561934e089 "/>
  8. <Section name ="WebRequestModules"
  9. Type = "System. Net. Configuration. WebRequestModuleHandler,
  10. System, Version = 1.0.3300.0, Culture = neutral,
  11. PublicKeyToken = b77a5c561934e089 "/>
  12. </SectionGroup>
  13. <SectionGroup name ="System. web">
  14. <Section name ="Authorization"
  15. Type = "System. Web. Configuration. AuthorizationConfigHandler,
  16. System. Web, Version = 1.0.3300.0, Culture = neutral,
  17. PublicKeyToken = b03f5f7f11d50a3a "/>
  18. <Section name ="SessionState"
  19. Type = "System. Web. SessionState. SessionStateSectionHandler,
  20. System. Web, Version = 1.0.3300.0, Culture = neutral,
  21. PublicKeyToken = b03f5f7f11d50a3a"
  22. AllowDefinition ="MachineToApplication"/>
  23. </SectionGroup>
  24. </ConfigSections>
  25. <System.net>
  26. <! -- Insert Net class settings here. -->
  27. </System.net>
  28. <System. web>
  29. <Authorization>
  30. <Allow users ="*"/><! -- Allow all users -->
  31. <! -- Allow or deny specific users.
  32. Allow users ="[Comma separated list of users]" 
  33. Roles ="[Comma separated list of roles]"/>
  34. <Deny users ="[Comma separated list of users]" 
  35. Roles ="[Comma separated list of roles]"/>
  36. -->
  37. </Authorization>
  38. <SessionState
  39. SqlConnectionString = "data source = localhost;
  40. Integrated Security = SSPI;
  41. Initial Catalog = northwind"
  42. Cookieless ="False"
  43. Timeout ="10"/>
  44. </System. web>
  45. </Configuration>

The ASP. NET configuration structure does not specify the configuration data types supported by the structure. The configuration section handler class processes all Web. config data. You can use the predefined configuration section handler provided by. NET Framework or create your own handler to process custom configuration data.

The content of the ASP. NET configuration file format will be introduced here, I hope to help you understand the format of the ASP. NET configuration file.

  1. Analysis on ASP. NET code optimization
  2. Analysis on the use of CustomValidator, an ASP. NET data verification control
  3. Analysis of embedded code block application in ASP. NET web pages
  4. Analysis on SQL Server Database Backup Recovery in ASP. NET
  5. Analysis of Theme functions in ASP. NET development skills

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.