2

I want to develop a new custom session state provider or use an existing (distributed caching, sql ...). Our main website renders more than 10 000 000 visits per day.It is really important for us to provide an easy rollback/switch in case of an error or a performance hit. Change web.config is not optimal because we have more than 20 front end servers. Our idea is to switch between session provider (from our custom to InProc) with a simple config in database.

Is it possible to have multiple session state providers or easily switch between providers ?

i found here http://netpl.blogspot.fr/2007/06/wrapped-inprocsessionstatestore.html, a solution for having a generic wrapper, but it does not seems quite robust.

Thanks,

Cybermaxs
  • 24,378
  • 8
  • 83
  • 112
  • I am not sure, why you think the linked solution is not robust. Also, as a fall back you should not be falling back to InProc as your web app is deployed in a web farm (20 front end servers) – Ramesh Jul 27 '12 at 02:40

2 Answers2

1

Just for future references, it is not possible to dynamically change the session state provider.

Cybermaxs
  • 24,378
  • 8
  • 83
  • 112
1

it is not.. totally true.. you can do it like this using Reflection:

var privateFieldFlags = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic;

//Get session state section
var sessionStateSection = ConfigurationManager.GetSection("system.web/sessionState") as SessionStateSection;
var values = typeof(ConfigurationElement).GetField("_values", privateFieldFlags).GetValue(sessionStateSection);
var entriesArray = values.GetType().BaseType.GetField("_entriesArray", privateFieldFlags).GetValue(values);

//Get "Mode" entry (index: 2)
var modeEntry = (entriesArray as System.Collections.ArrayList)[2];
var entryValue = modeEntry.GetType().GetField("Value", privateFieldFlags).GetValue(modeEntry);

//Change entry value to InProc
entryValue.GetType()
        .GetField("Value", privateFieldFlags)
        .SetValue(entryValue, System.Web.SessionState.SessionStateMode.InProc);

references:
Dynamic session state provider
http://www.answerandquestion.net/questions/4447903/dynamic-session-state-provider

Community
  • 1
  • 1
sanchezis
  • 429
  • 4
  • 9