2010-06-08 83 views
2

我做了一個.net 2.0庫項目,導致了一個dll。我在我的項目中創建了一個app.config文件,並在dll中使用了一些設置,目的是可以在以後更改它們。asp.net網站中的DLL配置文件

我試圖現在在一個asp.net web應用程序中使用dll,所以我做了我的其他項目的輸出的引用,我看到該dll被複制到該網站的bin文件夾,並且一切正常。但是,配置文件不會被複制。當我手動複製app.config並將其重命名爲myDll.config時,它沒有任何影響。

配置文件的內容大約是這樣的:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <configSections> 
     <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > 
      <section name="myDLL.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
     </sectionGroup> 
    </configSections> 
    <applicationSettings> 
     <myDLL.My.MySettings> 
       <setting name="myDLL_webservice_Service" serializeAs="String"> 
         <value>https://myhost/Service.asmx</value> 
       </setting> 
       <setting name="ID" serializeAs="String"> 
         <value>6</value> 
       </setting> 
     </myDLL.My.MySettings> 
    </applicationSettings> 
</configuration> 

我在DLL中使用它的設置與此(vb.net代碼):

Private _id As Long = My.Settings.ID 

我怎樣才能把我的配置信息的地方,所以它可以使用?

  • 在網站應用程序的web.config中? 只有appSettings部分,它使用語法。它似乎並沒有工作。

  • 在我創建並使用的自定義文件格式中? 不是說漂亮..

回答

4

把你的configSections和你的applicationSettings(這些不同於appSettings)放在你的web.config文件中。

+0

謝謝,這工作:D我必須確保configSections是配置標記的第一個孩子,否則.net抱怨configSections已被定義,但沒關係。 – Tominator 2010-06-08 10:07:54

+0

是的,configSections是配置文件中的特例,.NET使用它來驗證當前配置文件中可以使用哪些部分。 – 2010-06-08 10:17:20

1

你只可以爲每個應用程序域中的一個配置文件。您需要合併它們,或手動將其加載爲explained here

+0

頁面鏈接也是有趣的系列,儘管有點長文本:)我會在截止日期之後閱讀它,謝謝! – Tominator 2010-06-08 10:08:36