Asp.Net Core 配置文件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Asp.Net Core 配置文件相关的知识,希望对你有一定的参考价值。

一 创建ConfigurationManager类

  public class ConfigurationManager
    
        public readonly static IConfiguration Configuration;
        static ConfigurationManager()
        
            Configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true).Build();
        

    

二 控制器内读取方式

   public class HomeController : Controller
    

        public IActionResult Index()
        
                     //读取
            string str=ConfigurationManager.Configuration["Logging:LogLevel:Default"];
            return View();
        
    

以上是关于Asp.Net Core 配置文件的主要内容,如果未能解决你的问题,请参考以下文章

[Asp.Net Core]Autofac支持配置文件

[Asp.Net Core]Autofac支持配置文件

Asp.Net Core 配置文件

Asp.Net Core 轻松学-玩转配置文件

记一个ASP.Net Core配置文件问题

[三] ASP.NET Core配置文件