编程语言
首页 > 编程语言> > Asp.Net Core 配置文件

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 readonly  IConfiguration Configuration;
        public HomeController(IConfiguration configuration)
        {
            Configuration = configuration;
        }
        public IActionResult Index()
        {
                     //读取
            string str=Configuration["Logging:LogLevel:Default"];
            return View();
        }
    }

标签:Core,配置文件,ConfigurationManager,IConfiguration,readonly,static,Net,Configuration,
来源: https://blog.51cto.com/12268222/2426246