views:

340

answers:

3

What are the best practices for updating a web application in IIS?

The first page you see when you visit our application is a login page.

What I want to achieve is that visitors be redirected to a page stating that the application is being updated. And for users with an admin role being able to login successfully (to check whether everything is working properly)

In web.config we keep track of wheter the application is being updated (updating = [true|false] and then on the authentication_event:

if (updating) 
{

   if (User.IsInRole("admin"))

   {

      redirect to main web app...

   }
   else
   {     

     redirect to web being updated page....

   }

}
else 
{

   redirect to main web app..

}

Any advise will be appreciated immensely..

A: 

Looks like you pretty much have it figured out.

if (WebConfigurationManager.AppSettings["updating"]=="true") 
   if (User.IsInRole("admin"))
       Response.Redirect("~/Main.aspx");
   else
       Response.Redirect("~/Updating.aspx");
else
   Response.Redirect("~/Main.aspx");
JoshJordan
A: 

instead of doing it via web.config, you should be saving the updating flag in some other xml file or database, as each time you update your web.config file, your application restarts, thus invalidating current application variables, caches, etc etc

apart from that, you got the other logic right. but avoid touching the web.config as far as possible - i personally only save the connection string in the web.config as that hardly changes

but rest of the key value pairs which change often, i have them saved in sql database table. so that way i never ever have to do an application restart unless my connection string changes :-)

Raj
Application Settings are made for just that sort of thing.
JoshJordan
depends. i do a lot of busy e commerce sites where at any point of time there are 100s of users busy shopping. i cant reset my entire app and loose them just to change the value of 1 app setting :-)
Raj
instead, what i do is in the admin section provide a form to site admin to update appSettings - and then just repopulate / refresh my class which holds these values - saved in application variable
Raj
ASP.NET already has that, using the ASP.NET Configuration Settings wizard. You can run this on a prod machine without writing any code. The whole point of Application Settings is not to have to restart :)
JoshJordan
you can edit the appSettings causing an app restart on edit in the machineConfig [ restartOnExternalChanges="false" ]
BigBlondeViking
+4  A: 

I test everything locally, then I use the built in app_offline.html file on production server. When this file is present it will be served to clients, in meantime I am uploading new content. When done, renaming app_offline.html to something different and the new app starts.

twk
+10 I wish I could upvote this more. App_Offline is QUICK and EASY and I LOVE IT!!!! You can even leave the file sitting on the web server as app_offline_disabled.html when not in use. It saved me so many hassles I used to have to try. Just follow these guidelines and you'll be set. http://weblogs.asp.net/scottgu/archive/2006/04/09/442332.aspx
Dillie-O
Quick note, it is app_offline.htm....not .html
Dillie-O