少年恃险若平地,独倚长剑凌清秋。这篇文章主要讲述ASP.NET Core 2.0 IHostEnvironment和IApplicationLifetime介绍相关的知识,希望能为你提供帮助。
IHostEnvironment获取程序信息
public void Configure(IApplicationBuilder app, IHostingEnvironment env) {app.Run(async (context) => { await context.Response.WriteAsync($"ApplicationName:{env.ApplicationName}"); await context.Response.WriteAsync($"ContentRootPath:{env.ContentRootPath}"); await context.Response.WriteAsync($"WebRootPath:{env.WebRootPath}"); await context.Response.WriteAsync($"是否开发环境:{env.IsDevelopment()}"); }); }
文章图片
IApplicationLifetime站点启动或关闭时的监控
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime applicationLifetime) { applicationLifetime.ApplicationStarted.Register(() => { Console.WriteLine("ApplicationStarted"); }); applicationLifetime.ApplicationStopped.Register(() => { Console.WriteLine("ApplicationStopped"); }); applicationLifetime.ApplicationStopping.Register(() => { Console.WriteLine("ApplicationStopping"); }); }
【ASP.NET Core 2.0 IHostEnvironment和IApplicationLifetime介绍】
推荐阅读
- AndroidGreenDao操作外部DB数据库文件
- springboot报错Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFac
- 浅谈call apply bind的区别
- [转]Easily Add a Ribbon into a WinForms Application
- Java Generic application
- 最近排查android webview https的发热耗电和加载速度慢问题解决
- 毕业设计心得与整理-APP-主题切换
- Mybatis的mapper.xml文件也是要加文件头的
- 如何将应用完美迁移至Android P版本