ASP.NETCORE 启动 停止配置事件

2024-10-12 07:15:10

1、打开Startup文件配置 public void Configure(IApplicationBuilder app, IHostingEnvironment 髫潋啜缅env,IApplicationLifetime aft) { aft.ApplicationStarted.Register(() => { Console.WriteLine("Started"); }); aft.ApplicationStopped.Register(() => { Console.WriteLine("ApplicationStopped"); }); aft.ApplicationStopping.Register(() => { Console.WriteLine("ApplicationStopping"); }); if (env.IsDevelopment()) { app.UseBrowserLink(); app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }

ASP.NETCORE 启动 停止配置事件
猜你喜欢