Enabling Session State on SharePoint Foundation 2010

Earlier today I was surprised to discover that the Enable-SPSessionStateService cmdlet and the associated service are not included in SharePoint Foundation. This is unfortunate because I have some bits that need session and they need to run on SPF as well as SharePoint Server.

I found this post that describes a method for enabling Session on the MSDN forums. However, I noticed right away that the prescribed modification used the httpModules section of web.config and that it required registering System.Web.SessionState.SessionStateModule as a managed module in IIS 7.0. This is not an optimal solution as it kind of blends classic mode with integrated mode in IIS 7.0.

In my humble opinion, the proper way to modify web.config is as follows:

  1. Add <add name=’Session’ type=’System.Web.SessionState.SessionStateModule’ /> to the configuration/system.webServer/modules element.
  2. Set the enableSessionState attribute of the configuration/system.web/pages element to true.
  3. Add <sessionState mode=’InProc’ /> to the configuration/system.web element.

     

That’s it! Session state now works in process. If you need to use a session service, modify the sessionState mode appropriately. Of course, don’t use session unless you absolutely must as it adds overhead.

Finally, you shouldn’t require anyone to make these changes by hand. I have added a sample WebApplication scoped feature Visual Studio 2010 solution to the downloads section.

Hopefully this saves you some time!
–Doug


 

Author: Doug Ware