MongoSessionStateStore 4.3.0

Install-Package MongoSessionStateStore -Version 4.3.0
dotnet add package MongoSessionStateStore --version 4.3.0
<PackageReference Include="MongoSessionStateStore" Version="4.3.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MongoSessionStateStore --version 4.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MongoSessionStateStore, 4.3.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install MongoSessionStateStore as a Cake Addin
#addin nuget:?package=MongoSessionStateStore&version=4.3.0

// Install MongoSessionStateStore as a Cake Tool
#tool nuget:?package=MongoSessionStateStore&version=4.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

This project is not built for ASP.NET Core, if you need a session provider for ASP.NET Core check this out.


1 - Install the nuGet package into your solution.

The current version is built in 4.5 version of .NET framework. To use the 4.0 version of .NET framework install the version 2.0.0 of this controller

2 - Into web.config file add a <connectionStrings> section as detailed following set connection parameters properly.

        <add name="MongoSessionServices"

3 - Configure the <sessionState> provider section as detailed following:

    <sessionState mode="Custom" customProvider="MongoSessionStateProvider">
        <add name="MongoSessionStateProvider"
             connectionStringName="MongoSessionServices" />

Now you can get started using MongoDB Session State Store.

Chose one of these serialization types: Bson (default) or RAW. See the documentation about types of serialization to select the most suitable for you and the advantages and disadvantages.

Bson serialization (default)

To get started working with Bson serialization you don't need to set any parameter to any value, it's the default serialization.

A helper class is included in the assembly with static extensions. It's strongly recommended to use these helpers as shown in the examples.

You can personalize all methods of this helper class following these instructions.

// Sets 1314 in key named sessionKey
Session.Mongo<int>("sessionKey", 1314);

// Gets the value from key named "sessionKey"
int n = Session.Mongo<int>("sessionKey");

/* Note that decimal values must be converted to double.
   For non primitive objects you can use the same helper methods. */

// Creates and store the object personSetted (Person type) in session key named person
Person personSetted = new Person()
		Name = "Marc",
		Surname = "Cortada",
		City = "Barcelona"
Session.Mongo<Person>("person", personSetted);

// Retrieves the object stored in session key named "person"
Person personGetted = Session.Mongo<Person>("person");

Also, for primitive types you can use a direct way (not recommended).

// Set primitive value
Session["counter"] = 1;

//Get value from another request
int n = Session["counter"];

RAW serialization

To get started working with RAW serialization you need to set the parameter SerializationType to RAW value in the web.config file. See parameters detail to view the documentation about all parameters and a complete example of the config string.

// Declare the objects with Serializable attribute.
public class Person
	public string Name { get; set; }
	public string Surname { get; set; }
	public string City { get; set; }
// The usage is the same as usual
Person personSet = new Person() { Name = "Marc", Surname = "Cortada", City = "Barcelona" };
Session["key"] = personSet;
Person personGet = (Person)Session["key"];
// Or even better
personGet = Session["key"] as Person;
if (personGet != null) {...}

For further information read about parameters config

Here you'll find all release notes

If you are moving from 3.X.X to 4.X.X, as a major release, keep in mind these compatibility notes.

If you are moving from 2.X.X to 3.X.X, as a major release, keep in mind these compatibility notes.

If you are moving from 1.X.X to 2.X.X, as a major release, keep in mind these compatibility notes.

To set sessions without expiration time do not use Session.Timeout value to 0 disable TTL index creation

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.3.0 7,478 2/25/2018
4.2.1 2,098 12/17/2016
4.2.0 1,494 10/2/2016
4.1.0 966 6/4/2016
4.0.0 872 2/10/2016
3.2.0 752 1/23/2016
3.1.0 1,020 12/23/2015
3.0.0 907 12/23/2015
2.1.0 903 12/19/2015
2.0.2 771 12/12/2015
2.0.1 1,119 8/8/2015
2.0.0 858 4/16/2015
1.0.0 1,619 2/23/2015

This release implements performance improvements. The test cases implemented in the project TestApplicationv2_0 are able to create 21.024 sessions using this release instead of 17.024 sessions using the previous one. Both performance tests did run during the same time and environment.