Duwamish learns how to configure web. config.

Source: Internet
Author: User
Web. config

[Update @] 2004.10.31

(1) Naming rules for each Tag Name:
The tag name and attribute name are in the camel case format. This means that the first character of the tag name is in lower case, and the first letter of any followed word is in upper case. The attribute value is in the Pascal case format, which means that the first character is in uppercase, and the first letter of any followed word is in uppercase. Except true and false, they are always in lower case.

(2) configuration level overview

All configuration information resides between the <configuration> and </configuration> root XML tags.
Configuration information between tags is divided into two main areas: configuration section processingProgramDeclare the region and configure the region.

<? XML version = "1.0" ?>   <! -- Can not -->
< Configuration >
<! -- ================== 1 ================================= =====! -->
<! -- Configuration section handler declaration area (must be placed at the top of the current node) -->
  < Configsections >

<Section name = "etetction" type =" system. configuration. namevaluefilesectionhandler, system, version = 1.0.5000.0, culture = neutral, publickeytoken = b77a5c561934e089 "/>

<! -- This section is not included in any namespace group -->
< Sectiongroup Name = "System. Web" >   <! -- Group by namespace -->
< Section Name = "Authorization"  
Type = "System. Web. configuration. authorizationconfighandler,
System. Web, version = 1.0.3300.0, culture = neutral,
Publickeytoken = b03f5f7f11d50a3a" />
< Section Name = "Sessionstate"  
Type = "System. Web. sessionstate. sessionstatesectionhandler,
System. Web, version = 1.0.3300.0, culture = neutral,
Publickeytoken = b03f5f7f11d50a3a"
Allowdefinition = "Machinetoapplication" />
</ Sectiongroup >

  </ Configsections >
<! -- = -->
<! -- ================================================== -->
<! -- Configuration section setting area -->
<! -- If the preceding configuration section does not have a region declared by the handler but inherits mechine. config by default
Add the group name <system. Web>
< System . Web >
< Authorization >
< Allow Users = "*" />   <! -- Allow all users -->
<! -- Allow or deny specific users.
Allow Users = "[comma separated list of users]"
Roles = "[comma separated list of roles]"/>
<Deny users = "[comma separated list of users]"
Roles = "[comma separated list of roles]"/>
</ Authorization >
< Sessionstate
Sqlconnectionstring = "Data Source = localhost;
Integrated Security = sspi;
Initial catalog = northwind"
Cookieless = "False"  
Timeout = "10" />
  </ System. Web >
<! -- The node names of mechine. config that do not have a group are:
System. runtime. remoting
System. Diagnostics
Therefore, they are missing a level during configuration.
<! -- =========================/2 ================================ === -->
</ Configruation >

(3) Configuration Principle


Handler declaration in configuration section
<Section name = "etetction" type =" system. configuration. namevaluefilesectionhandler, system, version = 1.0.5000.0, culture = neutral, publickeytoken = b77a5c561934e089 "/>
The name attribute of this section indicates the name of the region to be set in the configuration section below.
The Type attribute is used by the specified class to process the fields in the configured area in the read configuration section. In fact, this type also defines the configuration format of the configured area in the configuration section. let's turn this format into a name/value pair.

For this type, the configuration format in the preceding example is as follows:
<Add key = "name" value = "caca"/>
<Add key = "email" value = "licunqing@gmail.com"/>

We can read the value of the key in this way.
String myname = system. configuration. configurationsettings. deleettings ["name"];
You can also read the values of all keys and return a set.
Namevaluecollection Config = (namevaluecollection) system. configuration. configurationsettings. getconfig ["etettings"];
String myname = config ["name"];
String myemail = config ["email"];

Therefore, we can create our own type. As for the region format set in the corresponding configuration section, we also use the system. configuration. namevaluefilesectionhandler format here.
Let's take a look at the examples in duwamish.
The configuration section declares that the region has a custom type:
<Section name = "duwamishconfiguration" type =" Duwamish7.common. duwamishconfiguration , Duwamish7.common "/>

The corresponding configuration section declaration format is:

<! -- Settings specific to the duwamish Application -->

<Add key = "duwamish. Web. enablepagecache" value = "true"/>

Obviously, the configuration section format is the name/value pair format mentioned above.

It seems that the type of this section is system. configuration. namevaluefilesectionhandler.

Look Duwamish7.common. duwamishconfiguration   Public   Class Duwamishconfiguration: iconfigurationsectionhandler
  // The original code is simplified here
  Public Object create (Object parent, Object Configcontext, xmlnode Section)

Namevaluecollection settings;

Namevaluesectionhandler basehandler =   New Namevaluesectionhandler ();
Settings = (Namevaluecollection) basehandler. Create (parent, configcontext, Section );

Return Settings;


Indeed, its essence is namevaluesectionhandler,Duwamish7.common. duwamishconfigurationCall it and return the result of calling it.
However, we can add something of our own here to control it well. For example, in duwamish, if the node configuration domain does not set those keys and corresponding values, let him return a default value. (See duwamish7.common. duwamishconfiguration)


[Adding and modifying...]
Search msdn: ASP. NET Configuration System/configuration file architecture for all information
Also look at duwamish'sSource code


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.