Publishing with Web Deploy causes Asp.Net Web Forms application to start and stop multiple times

169 views Asked by At

I have a Web Forms application running in IIS on a Windows Server 2016 dedicated server. Whenever I publish a new version to the server via Visual Studio's Web Deploy, the remote application starts and stops multiple times, which causes various errors during startup and, generally, a longer startup time.

I am logging the Application_Start and Application_End "events" in Global.asax. A typical log output that shows the problem looks like this:

[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

First thing that comes into my mind: Application_Start is called slightly before the running application even ends. And then multiple startup-processes seem to be running concurrently.

The " Synchronous part..." messages show that these separate processes are running for quite some itme before being terminated by a shutdown (I guess...). Another thing I should mention is that this behavior does not occur when the application pool is recycled by IIS or when I manually restart the application via IIS Stop/Start or Restart. That's why I suppose this has something to do with the way Web Deploy performs updates.

Can anyone provide me with an explanation for this behavior? I'd like to get rid of it since it might be causing problems further down the line.

Edit: Is it possible that changes to the \App_Data or a custom \Logs folder during startup can cause BinDirChangeOrDirectoryRename? According to other SO threads, this only happens due to a (now fixed) bug on Windows Server 2012, so ... ?

Edit 25.06.2021: Problem remains unsolved. I have now changed my Web Deploy publish profile so set the "EnableMSDeployAppOffline" flag which causes a clean shutdown of the running application before it is updated. But still, the Application_Start event is fired multiple times.

0

There are 0 answers