Access .NET Core Configuration Class From Another Assembly

后端 未结 2 1274
感情败类
感情败类 2021-01-20 10:59

In The Olden Days

In a web.config file, settings could be placed in an appSettings section like so:


  

        
2条回答
  •  鱼传尺愫
    2021-01-20 11:27

    In 8-2017 Microsoft came out with System.Configuration.Manager for .NET CORE v4.4. Currently v4.5 and v4.6 preview.

    Install this nuget package. Add directive to a code file

    using System.Configuration;
    

    Now, you can do your

    var val = ConfigurationManager.AppSettings["mysetting"];
    

    There is one trick for web sites though - you no longer use web.config for application settings and configuration sections. You use app.config as well as other types of projects. But if you deploy in ISS, you might need to use both. In web.config you supply strictly ISS-related entries. Your app-specific entries go to app.config

提交回复
热议问题