我有一个在 Windows Server 2016 专用服务器上的 IIS 中运行的 Web 窗体应用程序。每当我通过 Visual Studio 的 Web Deploy 向服务器发布新版本时,远程应用程序会多次启动和停止,这会导致启动过程中出现各种错误,并且通常会导致启动时间较长。
我正在 Global.asax 中记录 Application_Start 和 Application_End “事件”。显示问题的典型日志输出如下所示:
[hh:mm:ss] [Message]
12:45:30 Application_Start[104]: Server started on WIN-<UserId>
12:45:31 Global.asax.Application_End[248]: Server shutdown. Reason: HostingEnvironment
12:45:43 Application_Start[104]: Server started on WIN-<UserId>
12:45:44 Application_Start[104]: Server started on WIN-<UserId>
12:46:15 Global.Application_Start[199]: Synchronous part of the startup took: 34685ms
12:46:15 Global.Application_Start[199]: Synchronous part of the startup took: 32002ms
12:46:18 Application_Start[104]: Server started on WIN-<UserId>
12:46:44 Global.Application_Start[199]: Synchronous part of the startup took: 27582ms
12:46:48 Global.asax.Application_End[248]: Server shutdown. Reason: BinDirChangeOrDirectoryRename
12:46:52 Global.asax.Application_End[248]: Server shutdown. Reason: ConfigurationChange
12:46:54 Application_Start[104]: Server started on WIN-<UserId>
12:46:55 Global.asax.Application_End[248]: Server shutdown. Reason: ConfigurationChange
12:47:15 Global.Application_Start[199]: Synchronous part of the startup took: 21097ms
我想到的第一件事是:Application_Start 在正在运行的应用程序结束之前被调用。然后多个启动过程似乎同时运行。
“同步部分......”消息显示这些单独的进程在被关闭之前运行了相当长的时间(我猜......)。我应该提到的另一件事是,当 IIS 回收应用程序池或通过 IIS 停止/启动或重新启动手动重新启动应用程序时,不会发生此行为。这就是为什么我认为这与 Web Deploy 执行更新的方式有关。
谁能给我解释一下这种行为?我想摆脱它,因为它可能会导致进一步的问题。
编辑:在启动期间对\App_Data或自定义\Logs文件夹的更改是否可能导致BinDirChangeOrDirectoryRename?根据其他 SO 线程,这只是由于 Windows Server 2012 上的(现已修复)错误而发生的,所以......?
编辑 25.06.2021:问题仍未解决。我现在已经更改了我的 Web 部署发布配置文件,因此设置了“EnableMSDeployAppOffline”标志,这会导致正在运行的应用程序在更新之前完全关闭。但是,Application_Start 事件仍然被触发了多次。