簡體   English   中英

多個App.Config文件

[英]Multiple App.Config files

我想分開我的app.config文件。 例如,我想將ServiceModel部分移動到同一項目中的另一個配置文件。 我怎樣才能做到這一點?

謝謝。

您應該能夠將configSource屬性設置為第二個文件(相對於第一個文件)的空元素。 請參閱此處了解如何為自定義部分啟用它。

我找到了方法。 我改變了這樣的標簽。

<system.serviceModel>
    <behaviors configSource="Behaviors.config">
    </behaviors>
    <services configSource="Services.config">
    </services>
    <bindings configSource="Bindings.config">
    </bindings>
    <extensions configSource="Extensions.config">
    </extensions>
  </system.serviceModel>

在我創建了Services.config文件后,我把它放了

<services>
  <service behaviorConfiguration="ServiceBehavior" name="EntLib31ExceptionTest.Service1">
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8001/ValidationService1/" />
      </baseAddresses>
    </host>
    <endpoint address="" 
               binding="wsHttpBinding" 
               bindingConfiguration="CustomBinding" 
               contract="EntLib31ExceptionTest.IService"    
               behaviorConfiguration="Validation"/>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>

我在Bindings,Behaviors,Extensions.config文件中所做的一樣。

它有效

使用這樣的東西:

<?xml version="1.0"?>    
<configuration>    
    <appSettings />    
    <connectionStrings/>    
    <system.web>    
        <compilation debug="false" strict="false" explicit="true" />    
    </system.web>    
    <appSettings file="externalSettings.config"/>    
</configuration>

據我所知,這是不可能的。

您可以做的是(如果我們談論WCF代理)在您的代碼中創建和配置您的代理。 這樣你就不需要serviceModel部分了。

現在只需為您需要的數據定義自己的自定義部分,然后將其放在配置文件之外。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM