Reading a key from the Web.Config using ConfigurationManager

后端 未结 10 1788
情书的邮戳
情书的邮戳 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:08

    Also you can try this line to get string value from app.config file.

    var strName= ConfigurationManager.AppSettings["stringName"];
    
    0 讨论(0)
  • 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"]
    
    0 讨论(0)
  • 2020-11-28 18:11

    If the caller is another project, you should write the config in caller project not the called one.

    0 讨论(0)
  • 2020-11-28 18:13

    Full Path for it is

    System.Configuration.ConfigurationManager.AppSettings["KeyName"]
    
    0 讨论(0)
  • 2020-11-28 18:14
      var url = ConfigurationManager.AppSettings["ServiceProviderUrl"];
    
    0 讨论(0)
  • 2020-11-28 18:17

    There will be two Web.config files. I think you may have confused with those two files.

    Check this image:

    click this link and check this image

    In this image you can see two Web.config files. You should add your constants to the one which is in the project folder not in the views folder

    Hope this may help you

    0 讨论(0)
提交回复
热议问题