Sunday, 3 March 2013

MongoDB ASP.NET Session Store Provider v1.1.0

Since I created the MongoDB ASP.NET Session State Store Provider (v1.0.0), a few things have moved on in the MongoDB C# Driver. I've pushed a number of changes up to the project on GitHub (which I've incremented to v1.1.0), so it now uses v1.7.0.4714 of the driver. There is no change to way it is configured in web.config, so if you are using v1.0.0 of my provider it should be painless. Of course, I'd recommend thorough testing first :)

The changes relate to:

web.config recap
These web.config settings have not changed, so should continue working as before.
    <add name="MongoSessionServices" connectionString="mongodb://localhost" />
        <add name="MongoSessionStateProvider"
             replicasToWrite="0" />
replicasToWrite is interpreted as follows: < 0 = ignored. Treated as 0.
0 = will wait for acknowledgement from primary node.
> 0 = will wait for writes to be acknowledged from (1 + {replicasToWrite}) nodes.

Please Note, per the MongoDB Driver docs, if (1 + {replicasToWrite}) equates to a number greater than the number of replica set members that hold data, then MongoDB waits for the non-existent members to become available (so blocks indefinitely).

It still treats write concerns as important, ensuring it waits for acknowledgement back from at least one MongoDB node.

As always, all feedback welcome.


  1. Does this work with the 1.8.1 driver? There were some updates that addressed write errors in 1.7.x

    1. I can't say I've tried it - 1.7 was the latest version at the time I updated/blogged this. Can't imagine there would be any breaking changes, but best thing to do would be to just try it

    2. Hi, I've verified that it works great on 1.8.1. Is there any additional mods that need to be made for using it with multiple sites in IIS sharing the same session table?

    3. It should all be OK, the ApplicationName will get pulled in for each site via System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath and this is used when manipulating session state in the db.

  2. Obviously you haven't worked on this for a while, but any change you want to update the driver and throw this up on nuget?



  3. Brilliant I was just looking for this. Well actually I was gonne write one myself, but now it seems I wont have to. Great!