.Net Core 配置文件appsettings

1.配置文件为appsettings

  在appsettings添加ConnectionStrings

{
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Warning"
    }
  },
  "ConnectionStrings": {
    "MovieContext": "Server=(localdb)\\mssqllocaldb;Database=Movie-1;Trusted_Connection=True;MultipleActiveResultSets=true"
  }
}

  我们在构造函数里面初始化使用调用语句

using Microsoft.AspNetCore.Mvc.RazorPages;using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Http;

namespace RazorPagesMovie.Pages
{
    public class ceshiModel : PageModel
    {
        public string Message { get; set; }
        private readonly string _connectionString;
        public ceshiModel(IConfiguration configuration)//构造函数
        {
            _connectionString = configuration.GetSection("ConnectionStrings")["MovieContext"];
        }
        public void OnGet()//Get请求调用此函数
        {
            Message = _connectionString;
        }
    }
}

 

.Net Core 配置文件appsettings

上一篇:Discuz论坛广告横幅大图在百度app内无法显示,百度app默认开启了广告屏蔽


下一篇:Android开发环境搭建