core Web中使用appsettings.json配置文件的实例详解(ASP.NET )


当前第2页 返回上一页

原配置

1

2

3

4

5

public void ConfigureServices(IServiceCollection services)

{

 // Add framework services.

 services.AddMvc();

}

自定义

1

2

3

4

5

6

7

8

9

10

11

public void ConfigureServices(IServiceCollection services)

{

 // Add framework services.

 services.AddMvc();

  

 // Added - uses IOptions<T> for your settings.

 services.AddOptions();

  

 // Added - Confirms that we have a home for our DemoSettings

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

}

然后把设置注入进相应的Controller后就可以使用了

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

public class HomeController : Controller

{

 private DemoSettings ConfigSettings { get; set; }

  

 public HomeController(IOptions<DemoSettings> settings)

 {

  ConfigSettings = settings.Value;

 }

  

 public IActionResult Index()

 {

  ViewData["SiteName"] = ConfigSettings.SiteName;

  return View();

 }

}

总结

以上就是core Web中使用appsettings.json配置文件的实例详解(ASP.NET )的详细内容!

返回前面的内容

相关阅读 >>

理解asp.net中多层架构

关于asp.net如何利用ajaxpro完成前端跟后台交互的实例分析

asp.net mvc中传参并绑定数据的实例教程

.net存储pdf、word和excel到数据库的方法详解

动态生成html表单的asp.net方法代码示例

asp.net core 之 identity入门

高性能缓存系统(memcached)的实例介绍

.net项目中上传大图片失败

asp.net+jquery如何实现省市二级联动功能的方法详解

asp.net webapi中 filter的使用以及执行顺序(收藏)

更多相关阅读请进入《asp.net》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...