小编Jam*_*nes的帖子

让ASP.Net Core关闭在IISExpress中触发ApplicationStopping事件

我知道有一个先前的问题,还有一个GitHub问题:https://github.com/aspnet/Hosting/issues/846似乎从Microsoft.AspNetCore.Server.IISIntegration 1.1解决.但是,尽管有这个版本,这似乎仍然无法在IISExpress中工作(我通过让它执行Debug.WriteLine并在ApplicationStopping和ApplicationStopped上写入日志文件来测试它).我正在使用工具托盘小部件关闭IISExpress.

我不确定我是否做错了,是否以这种方式关闭IISExpress作为'正常关闭'来触发这些事件.看起来这可能在IIS中运行良好,但你无法在本地使用ASP.Net Core和完整的IIS进行开发,所以我想知道是否有任何方法可以在开发环境中触发这些事件进行测试?

这是Startup.cs中的代码:

public void Configure(IApplicationBuilder app, IApplicationLifetime life, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        // other configure code here

        life.ApplicationStopping.Register(() =>
            Debug.WriteLine(">>Stopping"));
        life.ApplicationStopped.Register(() =>
            Debug.WriteLine(">>Stopped"));
    }
Run Code Online (Sandbox Code Playgroud)

c# iis-express kestrel-http-server asp.net-core

25
推荐指数
1
解决办法
2488
查看次数