【问题标题】:Pass in Keys dynamic from app.config file从 app.config 文件传入动态密钥
【发布时间】:2018-11-20 23:29:51
【问题描述】:

我在配置文件中有以下键,我想从配置文件中动态地将“添加键”传递给我的 conn 变量,我可以传入 qp.cat.qmgr 成功,在我的 conn 变量中,我想知道如何将其他键传递给我的变量我是否从 .config 中传递下一个键,例如 +“qp.cat.quser”,即

var conn = new RabbitMqConnection(Helpers.AppSettings.Get<string>("qp.cat.qmgr") + ("qp.cat.quser") + ("qp.cat.qpassword"));

var conn = new RabbitMqConnection(Helpers.AppSettings.Get<string>("qp.cat.qmgr"), "theTestingUAT", "catquat"); //this works but "theTestingUAT" and "catquat" is hard coded, dont want them to be hardcoded

    <add key="qp.cat.qmgr" value="thetest:5444" />
    <add key="qp.cat.quser" value="theTestingUAT" />
    <add key="qp.cat.qpassword" value="catquat" />

请指教。

【问题讨论】:

    标签: c# model-view-controller key app-config


    【解决方案1】:

    你应该这样使用它:

    //Helpers.AppSettings.Get<string>("qp.cat.qmgr")
    //Helpers.AppSettings.Get<string>("qp.cat.quser")
    //Helpers.AppSettings.Get<string>("qp.cat.qpassword")
    
    var conn = new RabbitMqConnection(Helpers.AppSettings.Get<string>("qp.cat.qmgr"), Helpers.AppSettings.Get<string>("qp.cat.quser"), Helpers.AppSettings.Get<string>("qp.cat.qpassword"));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-11
      • 2011-04-19
      • 2020-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-09
      相关资源
      最近更新 更多