相关疑难解决方法(0)

如何使用ConfigurationElementCollection实现ConfigurationSection

我正在尝试在项目中实现自定义配置部分,并且我一直在遇到我不理解的异常.我希望有人能填补这里的空白.

App.config看起来像这样:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="ServicesSection" type="RT.Core.Config.ServicesConfigurationSectionHandler, RT.Core"/>
    </configSections>
    <ServicesSection type="RT.Core.Config.ServicesSection, RT.Core">
            <Services>
                <AddService Port="6996" ReportType="File" />
                <AddService Port="7001" ReportType="Other" />
            </Services>
        </ServicesSection>
</configuration>
Run Code Online (Sandbox Code Playgroud)

我有一个ServiceConfig像这样定义的元素:

public class ServiceConfig : ConfigurationElement
  {
    public ServiceConfig() {}

    public ServiceConfig(int port, string reportType)
    {
      Port = port;
      ReportType = reportType;
    }

    [ConfigurationProperty("Port", DefaultValue = 0, IsRequired = true, IsKey = true)]
    public int Port 
    {
      get { return (int) this["Port"]; }
      set { this["Port"] = value; …
Run Code Online (Sandbox Code Playgroud)

c# configuration app-config configuration-files

157
推荐指数
5
解决办法
14万
查看次数

使用ConfigurationManager从任意位置加载配置

我正在开发一个数据访问组件,该组件将用于包含经典ASP和ASP.NET页面混合的网站,并且需要一种管理其配置设置的好方法.

我想使用自定义ConfigurationSection,对于ASP.NET页面,这非常有用.但是当从传统的ASP页面通过COM interop调用组件时,组件不会在ASP.NET请求的上下文中运行,因此不了解web.config.

有没有办法告诉ConfigurationManager只需从任意路径加载配置(例如,..\web.config如果我的程序集在/bin文件夹中)?如果有,那么我认为我的组件可以回退到如果默认ConfigurationManager.GetSection返回null我的自定义部分.

任何其他方法都欢迎!

asp.net configuration asp-classic

121
推荐指数
5
解决办法
10万
查看次数

自定义ConfigurationSection

我使用IConfigurationSectionHandler接口来获取有关我的自定义配置部分的信息.但它已被弃用,我想改用ConfigurationSection.

如何使用此视图创建自定义ConfigurationSection并使用ConfigurationSection而不是IConfigurationSectionHandler:

<CustomSectionBlaBla>
   <Parent name="DB">
       <FirstChild value="someValue"/>
       <SecondChild value="someValue"/>
   <Parent/>
    ...
   <Parent name="UI">
       <FirstChild value="someValue"/>
       <SecondChild value="someValue"/>
   <Parent/>
<CustomSectionBlaBla/>
Run Code Online (Sandbox Code Playgroud)

.net c# configuration configurationsection

13
推荐指数
2
解决办法
8595
查看次数