我知道之前有一个关于此问题的问题,还有一个 GitHub 问题:https://github.com/aspnet/Hosting/issues/846 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"));
}
我有一个包含所有最新 NuGet 更新的应用程序,并且可以验证 ApplicationStopped 和 ApplicationStopping 是否在 IISExpress 下触发。 ApplicationStarted 似乎工作正常。
我发现如果您直接在我的开发环境中调用应用程序,一切都很好。
本文 https://andrewlock.net/configuring-urls-with-kestrel-iis-and-iis-express-with-asp-net-core/告诉你如何做。
这很简单,只需从下拉框中选择应用程序即可:
我意识到这与使用 IIS Express 不同,但可能会帮助您解决问题。
Nearly forgot, to invoke you need to type Ctrl+C in the command window which appears when you start your app.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)