How to enable Session State on SharePoint Foundation 2010

I am in the middle of a large project involving Microsoft SharePoint Foundation 2010. The rollout consists of many custom processes developed using ASP.NET. Recently I began working on a custom web part project that utilized the Report Viewer control. This web part was actually a coplex web page that I had already written and was converting into a reporting web part for the company. The conversion process went fine, but when deploying the solution to the development server, I received this error whenever I added the web part to a page: “Session state has been disabled for ASP.NET. The Report Viewer control requires that session state be enabled in local mode.”

I did a ton of research online to find out what that error was all about. As you can imagine, there are a ton of postings out there on how to enable Session State for SharePoint 2010. The problem comes in when you consider the different versions of SharePoint 2010. The version I am working with is SharePoint Foundation 2010. Just doing a search on SharePoint 2010 returns a ton of posts about using Powershell to enable session state.

If you have been searching for information on how to enable session state in SharePoint 2010 then you are familiar with the powershell cmdlet Enable-SPSessionStateService.

That is the cmdlet I kept reading was the secret to getting session state going on my SharePoint server. The problem is that when I followed the directions for enabling session state using powershell, I could not find the cmdlet. I spent a ridiculous amount of time trying to figure this out since I had the correct powershell snapin, but I could not find that cmdlet.

Turns out that the cmdlet I was looking for is only available when you have SharePoint 2010, not SharePoint Foundation 2010. SharePoint 2010 is the version that requires a license to be purchased for use. It took a long time to find a Microsoft discussion thread where others were having this issue and the response way down from someone at Microsoft was that the cmdlet was only available on the licensed versions of SharePoint 2010. SharePoint Foundation 2010 requires you to enable session state manually. That was all there was to the post. No mention of how to enable this sort of thing manually, just that statement. I began to search for how to enable session state manually and got a ton of suggestions, but none of them were working until I fell upon one site.

First, you need to edit the web.config file of the SharePoint application. I did this by using IIS7, right clicking on the SharePoint site and choosing explore. The window that opens is the application root, and I used the web.config here to enable session state. This turns on session state for the entire application, which some people feel very strongly about the performance hit that can cause. This was a development machine, so I did not care, but be advised of the ramifications and do the research of the performance hit on using session state if necessary.

In the <system.web> section, find the <httpModules> element and edit it like the following:

<httpModules>

<add name = “Session” type=”System.Web.SessionState.SessionStateModule” />

</httpModules>

You also need to find the element tag <pages> (also under the <system.web> element) and look for the attribute called enableSessionState and set it to true if it is currently false. Save and close the web.config file.

You should then open the IIS 7 manager, and select your web application.

Open the modules applet under the IIS section.

Click “Add Managed Module” in the right hand panel.

Enter a name for the module, I chose “SessionState”, you can pick what you like, but I suggest something related to session state and then in the lower box, select the entry for:

System.Web.SessionState.SessionStateModule, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

I then added the module and restarted IIS, although a restart may not be necessary. I tried my page again and the web part worked fine, and the report viewer loaded with no issue. I hope this helps someone, as I spent a ridiculous amount of time trying to find an answer. I found this information at this location: http://social.msdn.microsoft.com/Forums/en/sharepoint2010general/thread/3145fd29-2315-42f7-8f9d-cf6d52dc3c95


This entry was posted in ASP.NET, Microsoft, SharePoint. Bookmark the permalink.