Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

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.

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?

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top