【问题标题】:Can I read all the connection strings from web.config without the names of each one? ASP.net我可以从 web.config 中读取所有连接字符串,而不需要每个字符串的名称吗? ASP.net
【发布时间】:2012-12-06 16:38:44
【问题描述】:

我想以编程方式从 web.config 读取所有连接字符串,而不指定连接字符串的名称。并将该信息用于不同目的,例如在屏幕上打印出来。有可能吗?我该怎么做?

谢谢,

【问题讨论】:

    标签: asp.net web-config connection-string


    【解决方案1】:

    你显然没有尝试任何东西。这样就可以了

      foreach (var s in System.Web.Configuration.WebConfigurationManager.ConnectionStrings)
      {
            Response.Write(s);
      }
    

    其中ConnectionStringsConnectionStringSettings 的集合

    foreach (System.Configuration.ConnectionStringSettings s in System.Web.Configuration.WebConfigurationManager.ConnectionStrings)
    {
         Response.Write(s);
    }
    

    【讨论】:

      猜你喜欢
      • 2011-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-26
      • 2019-02-21
      相关资源
      最近更新 更多