转:http://www.yongfa365.com/Item/using-configSource-Split-Configs.html

大型项目中,可能有多个Service,也就是会有一堆配置,而这些配置文件如果散落在各个项目的web.config里,那维护量将是非常巨大的,所以有人使用configSource将各咱文件分开放,然后Copy到各处,这样以来配置文件看起来就很模块化了,但这样Copy维护起来还是很麻烦,所以有高人提出公共配置的概念,将这些配置文件放到一个公用目录,然后在各个目录下建立一个虚拟文件夹指向那个公共目录(Junctionhttp://technet.microsoft.com/en-us/sysinternals/bb896768.aspx,如想了解更多可访问:多站点共享:共享配置)天下太平了,要添加修改只用改这一个文件夹的内容就可以了。

我们用到的有:

    <appSettings configSource="VConfigs\DEV\appSettings.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>

参考内容:

Spliting WCF config files

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 an external file for that section. Using an external configuration source can be useful in many scenarios. For instance, you could 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' cannot 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 could 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"

maxReceivedMessageSize="65536">

<readerQuotas maxDepth="32"

maxStringContentLength="8192"

maxArrayLength="16384"

maxBytesPerRead="4096"

maxNameTableCharCount="16384" />

<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>

引用:

在web.config里使用configSource分隔各类配置

http://www.yongfa365.com/item/using-configSource-Split-Configs.html

在web.config里使用configSource分隔各类配置的更多相关文章

  1. web.config里面使用configSource

    在asp.net中如果修改了配置文件web.config以后,会导致应用程序重启,所有回话(session)丢失掉,在 .NET Framework 2.0 以后的版本中,可以在一个单独文件中包括所有 ...

  2. web.config中的configSource

    在大型项目中,可能存在第三方类库的配置如:log4.net,AOP框架Unity,WCF等,或是自定义的配置,造成web.config内容过多,不易维护,影响Config初始化. 这时我们可以使用co ...

  3. net 中web.config单一解决方法 (其他配置引入方式)

    近期一个项目需要写许多的配置项,发现在单个web.config里面写的话会很乱也难于查找 所以搜了一下解决了,记录下来 一.   webconfig提供了引入其他config的方式 <conne ...

  4. 如何修改Web.Config里面的值

    0.先添加 <add key="MAXNUM" value="6" /> 1.读取值 string maxNum = ConfigurationMa ...

  5. asp.net Web.config 在不同版本的IIS配置的IHttpHandler的访问路径,以及经典模式和集成模式不同的配置

    如果IIS7.0使用.net4.0以上版本的框架,<system.web>中的httpHandlers节点就没有用了,而应该使用微软专为.net4.0以上版本设计的新节点<syste ...

  6. 使用 ConfigSource 特性 拆分 Web.config 文件

    一个大项目里可能会有非常多个配置参数,有.Net自己支持的配置(比如WCF,AppSettings),还有一部分是自定义的配置(比如继承自ConfigurationSection和Configurat ...

  7. 通过configSource提高web.config配置灵活性

    很多时候我们会有这样的情况,开发环境和测试环境中的配置文件是不一样的,最明显的就是数据库连接串,这样,每次我们发布一个测试版本,都要手动去修改一下配置文件,是不是很麻烦的说.其实利用web.confi ...

  8. web.config及<customErrors>节点之说明

    Web.config文件是一个XML文本文件,它用来储存ASP.NETWeb 应用程序的配置信息(如最常用的设置ASP.NETWeb 应用程序的身份验证方式),它可以出现在应用程序的每一个目录中.当你 ...

  9. 配置子目录Web.config使其消除继承,用虚拟目录创建多个网站的方法

    来源:http://www.wtnzone.com/post/2011/02/20/Set-Web-Config-to-Turn-Inheritance-Off.aspx ASP.NET提供了强大的W ...

随机推荐

  1. ZOJ 3778 Talented Chef(找规律,模拟计算,11届ACM省赛,简单)

    题目链接 2014年浙江省赛C题,当时觉得难,现在想想这题真水.. 找规律: 若   最大的那个步骤数*m-总和>=0,那么答案就是 最大的那个步骤数 . 否则  就要另加上不够的数量,具体看代 ...

  2. Spring整合Ibatis

    Spring整合Ibatis javaibatisspring 所需jar清单           ibatis-2.*.jar    *为任意版本,下同,ibatis工作包           sp ...

  3. IE插件DebugBar如何安装及使用

    DebugBar插件是一款功能很强大的IE插件,用户可以从各个不同的角度剖析Web页面内部,包括页面 详细代码.CSS样式表.所有链接.所有图片代码.脚本信息等等,不管你是编程大虾还是IT新人都和适合 ...

  4. CAS(Compare and Swap)理解

    什么叫CAS(Compare and Swap)?  硬件同步原语!! 什么蛋疼的名字,一般人很难理解.根据英文全称翻译==比较与交换,这个名字大致还能理解一点,目前先暂且这么理解吧. 有啥用处? 对 ...

  5. Hadoop-eclipse-plugin插件安装

    Hadoop-eclipse-plugin插件安装 学习Hadoop有一段时间了,以前每次的做法都是先在win下用eclipse写好Mapreduce程序,然后打成jar文件,上传到linux下用ha ...

  6. Project Euler 90:Cube digit pairs 立方体数字对

    Cube digit pairs Each of the six faces on a cube has a different digit (0 to 9) written on it; the s ...

  7. 欧拉工程第74题:Digit factorial chains

    题目链接:https://projecteuler.net/problem=74 数字145有一个著名的性质:其所有位上数字的阶乘和等于它本身. 1! + 4! + 5! = 1 + 24 + 120 ...

  8. phantomjs使用说明

    phantomjs使用说明 12条评论   phantomjs实现了一个无界面的webkit浏览器.虽然没有界面,但dom渲染.js运行.网络访问.canvas/svg绘制等功能都很完备,在页面抓取. ...

  9. vs2012 arcgis engine 10 丢失arcgis模板

    1.Visual Studio 2012环境下安装ArcGIS Engine 10 Visual Studio 2012环境下安装ArcObject SDK for the Microsoft .Ne ...

  10. jdbc知识问答 分类: 面试 2015-07-10 22:05 5人阅读 评论(0) 收藏

    1 JDBC连接数据库6步 Load the JDBC Driver Establish the Database Connection Create a Statement Object Execu ...