0
我創建了一個自定義類,從System.Configuration.ConfigurationSection
繼承,像這樣實現的(這顯然只是爲了獲得真正的配置運行):ASP.NET自定義配置節從引用的項目不工作?
public class Config : ConfigurationSection
{
[ConfigurationProperty("quoteOfTheDay", DefaultValue = "It is what it is.", IsRequired = false)]
public string QuoteOfTheDay
{
get
{
return this["quoteOfTheDay"] as string;
}
}
[ConfigurationProperty("yourAge", IsRequired = true)]
public int YourAge
{
get
{
return (int)this["yourAge"];
}
}
}
類的完整的命名空間+名是MyApp.Core。配置,它位於在編譯的MyApp.Core.dll組裝MyApp.Core項目。我然後從我的ASP.NET/MVC3項目,該項目被稱爲MyApp.UI引用這個項目。我已經編輯了Web.config
文件,添加sectionGroup
和section
內容是這樣的:
<configSections>
<sectionGroup name="myAppConfigGroup">
<section name="myAppSection"
type="MyApp.Core.Config, MyApp.Core, Version=1.0.0.0, Culture=neutral, PublicKey=null"
allowLocation="true"
allowDefinition="Everywhere" />
</sectionGroup>
</configSections>
<myAppConfigGroup>
<myAppSection>
</myAppSection>
</myAppConfigGroup>
但是,它似乎並不喜歡的類型MyApp.Core.Config
習慣驗證配置或提供智能影音意義,因爲我編輯的組態。這裏的一些看法我做:
- 我所定義的
yourAge
財產IsRequired = true
和應用程序運行正常,沒有它。 - 我甚至可以改變類型(有些類型根本不存在像Foo.Bar)在
<section>
元素,一切仍然運行良好 - 但如果我刪除
<section>
元素,應用程序不跑。
我百思不得其解,任何幫助嗎?