Configure ASP.NET Session State Provider with Config Transformations
We're excited that so many developers are using AppHarbor to scale .NET applications on our cloud platform. With great power comes great responsibility however, and as we pointed out when scaling was launched in beta, you have to carefully manage any state that has to be shared between multiple web workers running your app.
In tandem with the original launch, we published a guide and an example app demonstrating how to store sessions using the Memcacher add-on. We have changed the sample from always using memcached (annoying, since that means you have to run memcached on your dev machine) to just using memcached when deployed in Release
mode. When running in Debug
mode the standard in-proc Session State Provider is used. This should make developing and maintaining applications using memcached for session state storage easier.
Below is the Web.Release.Config transformation that you can use to configure the Memcached Session State Provider when an app is deployed to AppHarbor. You don't have to change anything, AppHarbor will automatically insert all relevant settings. Remember that you can test your config transformations if you need to incorporate additional transformation logic.
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<configSections>
<section name="cacheProvider" type="MemcachedProviders.Cache.CacheProviderSection, MemcachedProviders"
allowDefinition="MachineToApplication" restartOnExternalChanges="true" xdt:Transform="Insert"/>
<sectionGroup name="enyim.com" xdt:Transform="Insert">
<section name="memcached" type="Enyim.Caching.Configuration.MemcachedClientSection, Enyim.Caching"/>
</sectionGroup>
</configSections>
<enyim.com xdt:Transform="Insert" >
<memcached protocol="Binary">
<servers>
<add address="foo" port="bar" />
</servers>
</memcached>
</enyim.com>
<cacheProvider defaultProvider="MemcachedCacheProvider" xdt:Transform="Insert">
<providers>
<add name="MemcachedCacheProvider"
type="MemcachedProviders.Cache.MemcachedCacheProvider, MemcachedProviders" defaultExpireTime="2000"/>
</providers>
</cacheProvider>
<system.web>
<sessionState cookieless="false" regenerateExpiredSessionId="true" mode="Custom"
customProvider="MemcachedSessionProvider" xdt:Transform="Insert">
<providers>
<add name="MemcachedSessionProvider"
type="MemcachedProviders.Session.SessionStateProvider,MemcachedProviders"
dbType="none" />
</providers>
</sessionState>
</system.web>
</configuration>