Configuration File web. config (1)

Source: Internet
Author: User
Tags configuration settings connectionstrings

The following is my learning experience in Asp.net. I have noted down my understanding of each knowledge point. please correct me if you have any errors!
ASP. NET configuration data is stored in XML text files. Each XML text file is named Web. config. The Web. config file can appear in ASP. NET.
In multiple directories of the application.
All ASP. NET configurations reside in the web. config file. Element. The configuration information in this element is divided into two main areas: the configuration section handler declaration area and the configuration section setting area.

Configuration section handler declaration Area

Configuration section handler declaration AreaResident in the web. config file Element. It contains the ASP. NET configuration of the Declaration section handler. Element. These configuration section handler declarations can be nested in To help organize configuration information. Generally,SectiongroupElement indicates the namespace to apply the configuration settings. For example, all ASP. NET configuration section handlers are

Group in the Section, as shown in the following code example.

<? XML version = "1.0" encoding = "UTF-8"?>
<Configuration xmlns = "http://schemas.microsoft.com/.NetConfiguration/v2.0">

<Configsections> <! -- The custom configuration section handler declaration is generally placed in configsections -->

<Section name ="Test"Type =" ...... "/>

< SectiongroupName =" Test1"
Type = "system. Web. configuration. systemwebsectiongroup, system. Web, version = 2.0.0.0, culture = neutral, publickeytoken = b03f5f7f11d50a3a">
<! -- <Section/> elements. -->

</ Sectiongroup>
</ Configsections>

<Appsettings> </appsettings>
<Connectionstrings configsource = ""> </connectionstrings>
<System. Web> <! -- Here is the declaration in the System Configuration section, such as authorization and authentication --> </system. Web>
<! -- Custom configuration section settings -->
<Test> </test>
<Test1>
<Section1> </Section1>
<Section2> </section2>
</Test1>
< /Configuration>

Note the above structure: the first is the configurations configuration section. In my understanding, it contains the custom configuration section and the slave machine. the configuration section added in config. The custom configuration section declares the processing function, including the section and sectiongroup nodes. Then, the application declares the appsonstrings and appsonstrings database connection configuration section. Later, the configuration section about the application system. The Handler declares system. Web, which contains the application authentication and authorization configuration section. The last step is to set all the configuration sections in the deployments section.
Configuration section handler declaration general format:
<Section name = "loggingsettings" type = "atoneweb. Common. configuration. loggingsettingssection, atoneweb. Common"/>
The configuration section sets the general format:
<Loggingformatters>
<Add name = "text formatter" type = "atoneweb. Logging. textformatter, atoneweb. Logging" template = "timestamp: {timestamp}
Message: {message}
Category: {category}
Priority: {priority}
Eventid: {eventid}
Severity: {severity}
MACHINE: {MACHINE}
Application domain: {appdomain}
Thread name: {threadname}
Extended properties: {Dictionary ({key}-{value}
)} "/>
</Loggingformatters>

Complex price comparison settings:
<Loggingsettings>
<Loggingcategoriessource>
<Add name = "general" switchvalue = "all">
<Listeners>
<Add name = "Event Log destination"/>
</Listeners>
</Add>
<Add name = "Data Access Events" switchvalue = "all">
<Listeners>
<Add name = "file destination"/>
</Listeners>
</Add>
</Loggingcategoriessource>
<Logginglisteners>
<Add name = "file destination" type = "atoneweb. Logging. filetracelistener, atoneweb. Logging" logformatter = "text formatter" logfilename = "logfile.txt"/>
<Add name = "Event Log destination" type = "atoneweb. Logging. eventstracelistener, atoneweb. Logging" Source = "yimodo" logformatter = "text formatter" logmachinename = "."/>
</Logginglisteners>
<Loggingformatters>
<Add name = "text formatter" type = "atoneweb. Logging. textformatter, atoneweb. Logging" template = "timestamp: {timestamp}
Message: {message}
Category: {category}
Priority: {priority}
Eventid: {eventid}
Severity: {severity}
MACHINE: {MACHINE}
Application domain: {appdomain}
Thread name: {threadname}
Extended properties: {Dictionary ({key}-{value}
)} "/>
</Loggingformatters>
</Loggingsettings>

Each configuration section in the configuration section setting area has a section handler declaration.Section HandlerIs used to implement The. NET Framework class of the API. The Section handler Declaration contains the name of the Configuration Setting section (for example ) And the name of the section handler class used to process the configuration data in this section (for example

). The following code example illustrates this point.

      <section name="pages"
type="System.Web.Configuration.PagesSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
</section>

You only need to declare the configuration section handler once. The Section handler of the default ASP. NET configuration section has been declared in the default machine. config file. Root web. config
Files and other configuration files in ASP. NET applications are automatically inherited from machine. config
The configuration handler declared in the file. You must declare a new section handler only when you create a custom section handler class to process the custom settings section.

The predefined ASP. NET
Configuration section.

Configuration section settings

The configuration section setting area is located after the configuration section handler declaration area, which contains the actual configuration settings.

By defaultConfigsectionsEachSectionAnd
SectiongroupAll have a specified configuration section element. You can
Systemroot\ Microsoft. NET \ framework \Versionnumber\ Config \ machine. config. Comments
File to view these default settings.

Configuration section elements can also contain child elements, which are processed by the same section handler as their parent elements. For example Element contains

Element. This element does not have a corresponding section handler because it consists PagesProcessing.

<Pages
Buffer = "true"
Enablesessionstate = "true"
Asynctimeout = "45"
<! -- Other attributes. -->
>
<Namespaces>
<Add namespace = "system"/>
<Add namespace = "system. Collections"/>
</Namespaces>
</Pages>
Example in the web. config file // from msdn

The following code example demonstrates the location where the preceding code example is applicable to the Web. config file. Please note that,PagesElement
NamespacesThe element does not have a configuration section handler declaration. This is because
System. Web. configuration. pagessectionSection handler ProcessingPagesSet all child elements of a section

<? XML version = "1.0" encoding = "US-ASCII"?>
<Configuration>

<! -- Configuration section-handler declaration area. -->
<Configsections>
<Sectiongroup name = "system. Web"
Type = "system. Web. configuration. systemwebsectiongroup, system. Web, version = 2.0.0.0, culture = neutral, publickeytoken = b03f5f7f11d50a3a">
<Section
Name = "pages"
Type = "system. Web. configuration. pagessection, system. Web, version = 2.0.0.0, culture = neutral, publickeytoken = b03f5f7f11d50a3a"
/>
<! -- Other <Section/> elements. -->
</Sectiongroup>
<! -- Other <sectiongroup/> and <Section/> elements. -->
</Configsections>

<! -- Configuration section Settings area. -->
<Pages
Buffer = "true"
Enablesessionstate = "true"
Asynctimeout = "45"
<! -- Other attributes. -->
>
<Namespaces>
<Add namespace = "system"/>
<Add namespace = "system. Collections"/>
</Namespaces>
</Pages>
<! -- Other section settings elements. -->

</Configuration>

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.