Using Memcached-backed SessionProvider
When scaling your application to multiple instances on AppHarbor, you have to be very careful to make sure that any application state is shared between all instances running your application.
This also applies to ASP.NET Session State which by default uses instance-local in-memory storage. To get around this, we recommend using a Memcached-based session state provider in combination with our Memcacher addon.
We have forked and updated the Memcached Providers project, originally by Fahad Azeem. The code, and an archive with prebuilt dlls, is available on GitHub. We have also published a simple application demonstrating session state shared between instances. In particular, you should check out the configuration in Web.Release.Config. Don't forget to provision the Memcacher addon for any applications using this technique. If you use the configuration from the example, the relevant Memcached connection information will be automatically overwritten when you deploy your application to AppHarbor.
Here are the steps you need to take:
- Add and reference the MemCached Providers in your project.
- Provision the MemCacher add-on to your application.
- Add this to your Web.Release.Config to configure the Memcached Providers when your app is deployed to AppHarbor.
There are alternative Session State modes, including using a Session State Server (not safe in a multi-tenant setup like AppHarbor's), using MS SQL Server (won't work on AppHarbor SQL Server instances because the provider requires SQL Server Agent Scheduled Jobs) and using MySQL (much slower than using Memcached). We recommend using the approach described above.