美文网首页
配置文件Configuration读取

配置文件Configuration读取

作者: FLCode | 来源:发表于2019-04-19 17:59 被阅读0次

appsettings.json增加:

"SiteConfig": {

    "Name": "flcode",

    "Info": "ASP.NET Core 开发及跨平台,配置文件读取"

  }

然后新建一个SiteConfig 类:

public class SiteConfig

    {

        public string Name { get; set; }

        public string Info { get; set; }

    }

 ConfigureServices 中添加Options 及对应配置:

services.Configure<SiteConfig>(Configuration.GetSection("SiteConfig"));

Controller 中读取:

public class HomeController : Controller

{

       public SiteConfig Config;

        public HomeController(IOptions<SiteConfig> option)

        {

            Config = option.Value;

        }

  }

相关文章

网友评论

      本文标题:配置文件Configuration读取

      本文链接:https://www.haomeiwen.com/subject/abucgqtx.html