2012-07-10 151 views
-3

我需要在我的Web.config文件中创建嵌套节,我找不到符合我的要求的任何示例。web.config中的嵌套节

<IPTests> 
    <Environment environment="DEV"> 
     <Machine machine="Web01"> 
     <SiteIP site="Sitecore" ip="10.10.2.191"> 
     </SiteIP> 
     </Machine> 
    </Environemnt> 
</IPTests> 

这是用于“健康检查”为不同的应用程序/网站。我需要检查所有不同网站使用的资源。我已经使用DNS完成了这项工作,但是现在我需要在我们的不同服务器的不同环境中执行此操作,方法是使用IP地址访问不同的服务器。

任何帮助将是伟大的!

这是我到目前为止。

public class IPTests : ConfigurationSectionGroup 
    { 
     [ConfigurationProperty("codeEnvironment")] 
     public CodeEnvironmentSection CodeEnvironment 
     { 
      get { return (CodeEnvironmentSection)base.Sections["codeEnvironment"]; } 
     } 
    } 

    public class CodeEnvironmentSection : ConfigurationSection 
    { 
     [ConfigurationProperty("environemnt")] 
     public ValueElement To 
     { 
      get { return (ValueElement)base["environemnt"]; } 
     } 
    } 

    public class MachineSection : ConfigurationSection 
    { 
     [ConfigurationProperty("machine")] 
     public ValueElement To 
     { 
      get { return (ValueElement)base["machine"]; } 
     } 
    } 

    public class SiteIPSection : ConfigurationSection 
    { 
     [ConfigurationProperty("site")] 
     public ValueElement To 
     { 
      get { return (ValueElement)base["site"]; } 
     } 

     [ConfigurationProperty("ip")] 
     public ValueElement To 
     { 
      get { return (ValueElement)base["ip"]; } 
     } 
    } 

    public class ValueElement : ConfigurationElement 
    { 
     [ConfigurationProperty("value")] 
     public string Value 
     { 
      get { return (string)base["value"]; } 
      set { base["value"] = value; } 
     } 
    } 
+5

[你有什么试过](http://mattgemmell.com/2008/12/08/what-have-you-tried/)? – 2012-07-10 18:09:51

+0

我一直在尝试使用这个前面的例子:http://stackoverflow.com/questions/5027284/nested-configuration-section-app-config但是我不能让它工作因为我的多个巢 – Staleyr 2012-07-10 18:17:15

回答

0

它看起来像你试图在你的web.config中存储信息数据库。如果这可能会改变,那么你不应该把它存储在这里。

的问题是,任何改变的web.config会导致您的网站重新启动,并重置用户会话缓存等

如果您正致力于将自己的部分,那么你可以通过创建做到这一点自定义ConfigurationSection类:

您可以在网络上搜索更多信息这个,因为有相当多的教程在那里。

+0

我' m在不同的服务,数据库,文件夹等上运行资源测试。我需要在不同的ips上运行这些测试(如果您愿意的话,这是一项健康检查测试)。并且信息不会经常改变,但如果这样做需要轻松更改,那就是为什么它在web.config文件中。 – Staleyr 2012-07-10 18:25:54

+0

够公平的,你可以把它放在一个容易支持嵌套元素的xml文件中 - 取决于你是如何使用ConfigurationSection类的烦恼:) – rtpHarry 2012-07-10 18:42:42

+0

非常非常恼火lol,但我只是一个新手实习生,是我的主管想要它的方式:/ – Staleyr 2012-07-10 18:48:40