/// <summary>
/// Creates a new instance of MongoDBSessionStateProvider
/// </summary>
/// <param name="useDotNetMemoryCache">Determines whether to use .NET's MemoryCache or CommonCore's Cache</param>
/// <returns>A new MongoDB Session State Provider</returns>
private MongoDBSessionStateProvider GetMongoDBSessionStateProvider(bool useDotNetMemoryCache)
{
string dotNetMemoryCacheName = null;
try
{
var mongoWebSection = ConfigurationManager.GetSection("mongoDbWeb");
var mongoSessionState = mongoWebSection.GetType().InvokeMember("SessionState", BindingFlags.GetProperty, null, mongoWebSection, null);
dotNetMemoryCacheName = mongoSessionState.GetType().InvokeMember("DotNetMemoryCacheName", BindingFlags.GetProperty, null, mongoSessionState, null) as string;
}
catch { }
if (useDotNetMemoryCache)
{
// Pull the name from the config, or else create one by default to ensure
// mongoDbSessionStateProvider uses the .NET MemoryCache
if (string.IsNullOrWhiteSpace(dotNetMemoryCacheName))
{
dotNetMemoryCacheName = "MongoDBMemoryCache";
}
}
else
{
dotNetMemoryCacheName = string.Empty;
}
var config = new System.Collections.Specialized.NameValueCollection(_ProviderSettings.Parameters);
config["dotNetMemoryCacheName"] = dotNetMemoryCacheName;
var provider = new MongoDBSessionStateProvider();
provider.Initialize(_ProviderSettings.Name, config);
return provider;
}