Use configSource in web. config to separate various configurations

Source: Internet
Author: User

ConfigSource Introduction 1:
In web. config:

<Myconfig configSource = "path \ xxx. config"/>


In the custom path \ xxx. config:

<Myconfig>
<Mmm> dd </mmm>
</Myconfig>

Note: The file path in configSouce can only be a relative physical path, that is, it can only be a backslash (\) and cannot be a slash (/).
When the website is running, modifying the Web. Config file will cause the site to restart, but modifying the xxx. Config file will not.

 
ConfigSource Introduction 2:
In a large project, there may be multiple services, that is, there will be a bunch of configurations, and these configuration files are scattered in the web of each project. config, the maintenance volume will be very huge, so some people use configSource to split the files and Copy them to different places, so the configuration file looks very modular, however, it is still very troublesome to maintain the Copy, so some people have proposed the concept of public configuration, put these configuration files in a public directory, then create a virtual folder under each directory to point to that public directory (Junctionhttp: // folder) The world is too peaceful, to add and modify the content of this folder only.

We use:

 

<Etetaskconfigsource = "VConfigs \ DEV \ appsetask. config"/> <system. serviceModel>
<Services configSource = "VConfigs \ DEV \ WCF. services. config"/>
<Bindings configSource = "VConfigs \ DEV \ WCF. bindings. config"/>
<Behaviors configSource = "VConfigs \ DEV \ WCF. behaviors. config"/>
<Client configSource = "VConfigs \ DEV \ WCF. client. config"/>
</System. serviceModel> reference: ConfigSource attribute on system. serviceModel section
The configSource attribute was firstly introduced in. NET framework 2.0 to support external configuration files.

This attribute can be added to any configuration section to specify a external file for that section. using an external configuration source can be useful in your scenarios. for instance, you cocould place a section into an external configSource if you need an easy method to swap settings for the section depending on the environment (development, test, or production ), or you need granular control over permissions.

Unfortunately, the system. serviceModel section group does not support this attribute. If you try to add it, you will receive the following exception:

The attribute 'configsource' can not be specified because its name starts with the reserved prefix 'config' or 'lock'

"ConfigSource" attribute is a property comes from the section Information class.
Every ConfigurationSection in. net framework 2.0 configuration scheme system
Has a property of a section Information where the config source is declared.

You can use this attribute on the different sections under system. serviceModel such as services, behaviors or bindings.

For instance, the configuration file cocould look like this,

<Configuration>

<System. serviceModel>

<Services configSource = "Services. config"/>


<Bindings configSource = "Bindings. config"/>


<Behaviors configSource = "Behaviors. config"/>


</System. serviceModel>

</Configuration>

And then, each file contains the corresponding section.

Services. config

<Services>

<Service name = "Microsoft. ServiceModel. Samples. CalculatorService"

BehaviorConfiguration = "CalculatorServiceBehavior">

<Host>

<BaseAddresses>

<AddbaseAddress = "http: // localhost: 8000/servicemodelsamples/service"/>

</BaseAddresses>

</Host>

<! -- This endpoint is exposed at: net. tcp: // localhost: 9000/servicemodelsamples/service -->

<Endpointaddress = "net. tcp: // localhost: 9000/servicemodelsamples/service"

Binding = "netTcpBinding"

BindingConfiguration = "Binding1"

Contract = "Microsoft. ServiceModel. Samples. ICalculator"/>

<! -- The mex endpoint is exposed at http: // localhost: 8000/ServiceModelSamples/service/mex -->

<Endpoint address = "mex"

Binding = "mexHttpBinding"

Contract = "IMetadataExchange"/>

</Service>

</Services>

Bindings. config

<Bindings>

<NetTcpBinding>

<Binding name = "Binding1"

CloseTimeout = "00:01:00"

OpenTimeout = "00:01:00"

ReceiveTimeout = "00:10:00"

SendTimeout = "00:01:00"

TransactionFlow = "false"

TransferMode = "Buffered"

TransactionProtocol = "OleTransactions"

HostNameComparisonMode = "StrongWildcard"

ListenBacklog = "10"

MaxBufferPoolSize = "524288"

MaxBufferSize = "65536"

MaxConnections = "10"

Maxcompute edmessagesize = "65536">

<ReaderQuotas maxDepth = "32"

MaxStringContentLength = "8192"

MaxArrayLength = "16384"

Maxbytesperread= "4096"

MaxNameTableCharCount = "16384" type = "parmname" text = "parmname"/>

<ReliableSession ordered = "true"

InactivityTimeout = "00:10:00"

Enabled = "false"/>

<Security mode = "Transport">

<Transport clientCredentialType = "Windows" protectionLevel = "EncryptAndSign"/>

</Security>

</Binding>

</NetTcpBinding>

</Bindings>

Behaviors. config

<Behaviors>

<ServiceBehaviors>

<Behavior name = "CalculatorServiceBehavior">

<ServiceMetadata httpGetEnabled = "true"/>

<ServiceDebug includeExceptionDetailInFaults = "False"/>

</Behavior>

</ServiceBehaviors>

</Behaviors>

 


From the big tree next to the grass

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.