Ihostenvironment Getting program information
Public voidConfigure (Iapplicationbuilder app, Ihostingenvironment Env) {app. Run (Async(context) = { awaitContext. Response.writeasync ($"applicationname:{env. ApplicationName}"); awaitContext. Response.writeasync ($"contentrootpath:{env. Contentrootpath}"); awaitContext. Response.writeasync ($"webrootpath:{env. Webrootpath}"); awaitContext. Response.writeasync ($"is the development environment: {env. Isdevelopment ()}"); });}
Iapplicationlifetime monitoring when the site starts or shuts down
Public voidConfigure (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"); });}
Introduction to ASP. 2.0 Ihostenvironment and Iapplicationlifetime