views:

183

answers:

5

I have a website in C#/ASP.NET that is currently in development. When we are in production, I would like to do releases frequently over the course of the day, as we fix bugs and add features (like this: http://toni.org/2010/05/19/in-praise-of-continuous-deployment-the-wordpress-com-story/).

If you upload a new version of the site or even change a single file, it kicks out the users that are currently logged in and makes them start over any forms and such. Is there a secret to being able to do deployments without interfering with users for .NET sites?

+4  A: 

The reason you're seeing this is because you are resetting the application pool, thus resetting everyone's session.

The cleanest route would be to offload your session to a session state server, or minimize your use of session.

One way around this is if you can't offload your session is to always deploy to a new virtual directory. Your public facing URL then just redirects to your latest version. All users that are already logged in would continue to use the older version, but any new users would use the new version.

AaronS
A: 

I suppose users are kicked because web-server application process is restarted. By default user sessions are stored in memory and session data is killed. Session provider is configurable option in web.config. May be choosing external (out-of-web-application-process) session provider is a step toward what you are expecting.

Andrew Florko
A: 

There are two alternatives to achieve that:

  1. Do not use Session at all. (You may use cookies for authentication)
  2. Use another Session-state mode. State server or SQLServer. http://msdn.microsoft.com/en-us/library/ms178586(v=VS.80).aspx

Either way you will also gain the flexibility to be able to run your application on multiple servers for performance or fail safe clustering.

hakan
A: 

Depending on what you store in the Session object, you may be able to reconstruct it in Global.asax's Session_Start handler. I used to do this in an internal application where we only really stored the user's identity in the Session, so we could just use their authorization cookie to recreate the session.

One thing to keep in mind if you do this: say a user loads up a form and then leaves for lunch, and you update that page while they are away. If they return to their desk and submit the form they'll be submitting the old version of the form to the new code-behind.

Cory Grimster
There is other state we need to store besides authenticatication, so moving to cookies/Global.asax won't be a solution for us.I think your second point is pretty painful. Not sure how companies who do continuous deployment handle that...
Amber Shah
I'm not sure either, but you'd have to do someting explicit and it would be a potential point of failure. Maybe some kind of versioning of forms, so the form can see if the user is posting and out-of-date form to an updated code-behind.Anyway, not something you have to worry about if you can't use the cookie approach anyway :)
Cory Grimster
+2  A: 

If you make a change to a config file, the contents of a bin folder of the app, or things like that, the ASP.NET worker process restarts along with your application.

This results in deleted sessions and kicked-out users.

The solution is to use other session storage methods other than the default InProc.
You can achieve this by setting the session state mode. The SqlServer and StateServer options provide very good remedy for your issue.

SqlServer mode is relatively easy to set up and get up and running. (Basically, it's just creating a database, running aspnet_regsql, and then specifying it to the config.) If you don't have MS SQL Server or don't want to use it, you can use StateServer, or create your own provider and use the Custom mode.

The only restriction is that you can only store serializable values with SqlServer and StateServer mode.

Venemo