Reading a key from the Web.Config using ConfigurationManager

后端 未结 10 1852
情书的邮戳
情书的邮戳 2020-11-28 17:55

I am trying to read the keys from the Web.config file in a different layer than the web layer (Same solution)

Here is what I am trying:

         


        
10条回答
  •  孤独总比滥情好
    2020-11-28 18:09

    Sorry I've not tested this but I think it's done like this:

    var filemap = new System.Configuration.ExeConfigurationFileMap();            
    System.Configuration.Configuration config =  System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(filemap, System.Configuration.ConfigurationUserLevel.None);
    
    //usage: config.AppSettings["xxx"]
    

提交回复
热议问题