.NET client and ASP.NET SessionStateProvider - important migration notes
I recently switched over from the older Membase namspaced .NET client and the memcached-providers .NET SessionStateProvider to the Couchbase .NET client and couchbase-aspnet. I ran into a few hiccups that might be useful for others and should maybe be mentioned in documentation somewhere.
First of all, Couchbase.Configuration.CouchbaseClientSection requires you leave the bucket name off of the URI.
What would formerly be:
<servers bucket="SessionState"> <add uri="http://localhost:8091/pools/SessionState" /> </servers>
<servers bucket="SessionState"> <add uri="http://localhost:8091/pools" /> </servers>
The next thing is that there's an undocumented "section" config attribute for the custom SessionStateProvider.
<sessionState customProvider="Couchbase" mode="Custom" timeout="500"> <providers> <add name="Couchbase" type="Couchbase.AspNet.SessionState.CouchbaseSessionStateProvider, Couchbase.AspNet" section="couchbaseSessionState" /> </providers> </sessionState>
The above config allows you to specify the config section that will apply to the SessionState. This likely doesn't matter if you just have the default "couchbase" config section, but if you're using multiple config sections for multiple buckets then this is invaluable.
Great to hear that you're using the Couchbase ASP.NET SessionState provider! You are correct that you should bootstrap off of /pools. Also, there's more information about multiple client configs in the development wiki at
Thanks for sharing your experinces...
In my case I actually store our Couchbase configuration in a totally separate XML configuration file from the Web.config. The reason for this is because we have so much other 'app' configuration stuff in our Web.config file that it makes it too complicated to maintain separate copies for every site that is running on our code. So rather we keep the Web.config file common to all sites that run the app, and store the site specific stuff in a SiteConfig.xml file for the site.
So we have or own mechanism for reading the Couchbase configuration and it was not entirely clear how to use the library verbatim for session storage. But looking through the code you can easily toss in your own factory that implements the ICouchbaseClientFactory interface with the following session state section in the config file:
<sessionState customProvider="Couchbase" mode="Custom"> <providers> <add name="Couchbase" type="Couchbase.AspNet.SessionState.CouchbaseSessionStateProvider, Couchbase.AspNet" factory="Couchbase.AspNet.SessionState.CouchbaseClientFactory" /> </providers> </sessionState>
This sample just points to the default CouchbaseClientFactory but you can replace that class with your own to be able to configure the client with your own configuration instead of expecting to get it from a section in the web.config file.