Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redeploying an ASP.NET site in IIS7 without files in use interfering

We've got a process currently which causes ASP.NET websites to be redeployed. The code is itself an ASP.NET application. The current method, which has worked for quite a while, is simply to loop over all the files in one folder and copy them over the top of the files in the webroot.

The problem that's arisen is that occasionally files end up being in use and hence can't be copied over. This has in the past been intermittent to the point it didn't matter but on some of our higher traffic sites it happens the majority of the time now.

I'm wondering if anyone has a workaround or alternative approach to this that I haven't thought of. Currently my ideas are:

  1. Simply retry each file until it works. That's going to cause errors for a short time though which isn't really that good.
  2. Deploy to a new folder and update IIS's webroot to the new folder. I'm not sure how to do this short of running the application as an administrator and running batch files, which is very untidy.

Does anyone know what the best way to do this is, or if it's possible to do #2 without running the publishing application as a user who has admin access (Willing to grant it special privileges, but I'd prefer to stop short of administrator)?

Edit
Clarification of infrastructure... We have 2 IIS 7 webservers in an NLB running their webroots off a shared NAS (To be more clear, they're using the exact same webroot on the NAS). We do a lot of deploys, to the point where any approach we can't automate really won't be viable.

like image 413
fyjham Avatar asked Mar 12 '10 06:03

fyjham


People also ask

How do I publish my website on IIS?

In IIS, right-click the Default Web Site, choose Deploy > Configure Web Deploy Publishing. If you don't see the Deploy menu, see the preceding section to verify that Web Deploy is running. In the Configure Web Deploy Publishing dialog box, examine the settings. Click Setup.

How can I see ASP.NET in IIS?

In Control Panel, click Programs, and then click Turn Windows features on or off. In the Windows Features dialog box, click Internet Information Services to install the default features. Expand the Application Development Features node and click ASP.NET 4.5 to add the features that support ASP.NET.


1 Answers

What you need to do is temporary stop IIS from processing any incoming requests for that app, so you can copy the new files and then start it again. This will lead to a small downtime for your clients, but unless your website is mission critical, that shouldn't be that big of a problem.

ASP.NET has a feature that targets exactly this scenario. Basically, it boils down to temporarily creating a file named App_Offline.htm in the root of your webapp. Once the file is there, IIS will takedown the worker process for you app and unload any files in use. Once you copy over your files, you can delete the App_Offline.htm file and IIS will happily start churning again.

Note that while that file is there, IIS will serve its content as a response to any requests to your webapp. So be careful what you put in the file. :-)

like image 91
Franci Penov Avatar answered Sep 23 '22 04:09

Franci Penov