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 core 发送邮件

asp.net之actionfilter过滤器

asp.net(一)基础三层框架项目:web服务器、业务服务器、数据库服务器

如何在不使用 webmatrix 的情况下发布 web pages?

asp.net中partial class部分类

基于calendar实现blog日历的实例详解

详细介绍asp.net core mvc项目实现多语言的示例代码

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

传播智客asp.net中级系列视频视频资料

asp.net数据库密码:md5加密算法详解

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




打赏

取消

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

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

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

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

评论

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

    正在狠努力加载,请稍候...