.net core 配置文件添加常量

(1)在appsettings.json文件中添加我们需要的系统信息。
   "Setting": {
    "Server": "111.11.1.1",
    "Port": 25,
    "UserId": "aaaa",
    "Password": "bbbb",
  }
(2)在startup.cs文件中的ConfigureServices函数添加配置注解
 services.Configure<Setting>(Configuration.GetSection("Setting"));
(3)建立一个Setting的模型文件
    public class Setting
    {
        public string Server { get; set; }


        public int Port { get; set; }


        public string UserId { get; set; }


        public string Password { get; set; }
    }
(4)在其他controller层添加注解就可以使用。

猜你喜欢

转载自blog.csdn.net/u012601647/article/details/71036419
今日推荐