Asp.net Core-IHostingEnvironment和IApplicationLifetime的使用

Posted .Neter

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Asp.net Core-IHostingEnvironment和IApplicationLifetime的使用相关的知识,希望对你有一定的参考价值。

IHostingEnvironment对象中是一些该应用程序的环境信息,包括程序名称信息,根目录,环境名称 等等基本信息

await context.Response.WriteAsync($"name="{env.ApplicationName}"");
await context.Response.WriteAsync($"name="{env.ContentRootFileProvider}"");
await context.Response.WriteAsync($"name="{env.ContentRootPath}"");
await context.Response.WriteAsync($"name="{env.EnvironmentName}"");
await context.Response.WriteAsync($"name="{env.WebRootFileProvider}"");

 

IApplicationLifetime对象是用来绑定应用程序的运行时事件的

applicationLifetime.ApplicationStarted.Register(() =>
            {
                Console.WriteLine("Strated");
            });
applicationLifetime.ApplicationStopping.Register(() =>
            {
                Console.WriteLine("Stoping");
            });
applicationLifetime.ApplicationStopped.Register(() =>
            {
                Console.WriteLine("Strated");
       }

 

 

 

未完待续...

以上是关于Asp.net Core-IHostingEnvironment和IApplicationLifetime的使用的主要内容,如果未能解决你的问题,请参考以下文章