views:

340

answers:

5

Does anyone have a sample of how to patch a running asp.net app? The scenario I'm envisioning is that the app could look to a known central server for newer versions. Download the newer files to a temp location and then patch itself.

The issues that I can see are that any file changes will get picked up by the file watcher and reload the app domain which would stop the current patching process. I think that each file written would trigger a reload of the app.

+3  A: 

What do you mean by patching?

If you mean updating, you can simply copy updates files to application directory. Currently active requests will be fully served using the last compiled version of your application, then it will be recompiled to serve the consequent requests. Nothing special is required really.

User
My concern is that a "patch" may consist of several hundred files. If the application is downloading the files and writing over it's own /bin folder and content folders I would expect the app domain to recycle many times over. What I'm trying to do is to delay the app domain restart until all the new files are in place.
Marcus McConnell
Just download them to a temp folder and overwrite from there? File copy from one folder to another one the same drive is pretty quick even for hundreds of files - certainly faster than any recompile would be for an app of that size.
Jon Grant
A: 

I don't know of any automated way to do this. It seems like it would be easier to just rely on an automated build script that would push out changes to your server(s).

If you keep session state in an external process, you can update the site (which will cause a re-compile) without your users being kicked out. They will only experience a longer load time as they wait for the re-compile.

Gabe Moothart
This would be for a commercial product sold to other so I would have no way to push changes via a build script. What I'm looking for is a way to offer updates to the latest version similar to ClickOnce apps. I think the issue may be too deep in the ASP.NET runtime to work around.
Marcus McConnell
A: 

I'd just check the version information when the filewatcher event is raised. If the version the assembly is different than the active assembly you are considering patching then you proceed with the copy. If not then simply ignore the event. Also the question would be why would you be copying to the temp directory that the files are being retreived from when there isn't an actual version change?

Achilles
The file watcher is inside the asp.net runtime. I don't create it and I don't think I can ignore the events.
Marcus McConnell
So do you use the filewatcher even to "know" when to copy the new files or are you talking about the nature of the framework to update a dll when its copied to the bin folder?
Achilles
+3  A: 

Unless you're doing some file watching on specific files, you can update existing aspx files without any application slowdown. The next time the user refreshes the browser, they'll see the page update. Be careful though, if you have added additional server controls to the page, and the DLL hasn't been updated yet, you'll run into problems.

If you update the web.config or DLL files for the application, this will trigger a reload of the ASPNET worker process, and any new users will suffer the "first lag" that you can typically expect.

If you are worried about this process, and can afford a bit of "down time" I'd suggest you create a script that does the following:

  1. Upload a file named App_Offline.htm to the root of the web application. IIS will immediately see this file and redirect users to it, and not do any .NET processing. You can even keep a file named App_Offline_Disabled.htm in the root folder and simply rename it when the time is right.

  2. Copy all your files in that need to be updated, overwriting/renaming/copying as necessary.

  3. Remove (or rename) your App_Offline.htm file so that IIS will start directing users to the updated application. If you're watching the script run, you can even go hit the website yourself to take that "first load" penalty so your end users will see things nice and crisp as always.

Again, I don't know if you can afford the down time on the site in this manner, but I see the process itself as easily scriptable to provide for a nice automated type process.

Dillie-O
I forgot about app_offline.htm. That will probably do the trick.
Marcus McConnell
Just remember to add a substantial decent amount of text into the file (needs to be greater that 512 bytes if memory serves) to prevent the friendly errors in IE from causing confusion on the users end.
Dillie-O
A: 

In case anyone else can't use the app_offline.htm trick I found this article which explains how to disable file monitoring for subfolders

http://www.dominicpettifer.co.uk/Blog/36/stop-iis-appdomain-restarts-when-a-folder-is-deleted

Marcus McConnell