0
点赞
收藏
分享

微信扫一扫

(1) .net6如何读取配置文件

杨小羊_ba17 2022-01-25 阅读 31

appsettings.json设置字符串

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "ConnectionStrings": {
    "SqlConn": "PORT=5432;DATABASE=WebApp;HOST=localhost;PASSWORD=123456;USER ID=postgres"
  }
}

Program.cs里写

IConfigurationRoot configuration = builder.Configuration;
var conn = configuration.GetConnectionString("SqlConn");
Console.WriteLine(conn);

输出:

PORT=5432;DATABASE=WebApp;HOST=localhost;PASSWORD=123456;USER ID=postgres
举报

相关推荐

0 条评论