Enable Session State in SharePoint 2010

If you are trying to use session state in SharePoint 2010 to store data for use in web parts, application pages, etc. you may encounter the error below if session state is not properly configured and enabled for the web application.

Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the \\<…

To resolve the error and to enable session state for SharePoint there are two entries that need to exist in the web.config file.

The first is to ensure that enableSessionState is set to TRUE.

Enable session state for all pages:

<pages enableSessionState="true" ... > 

Add the SessionStateModule

<modules runAllManagedModulesForAllRequests="true">
 <remove name="Session" />

Once you have made the modifications above to the web.config file you need to ensure that the State Service service application is running.

I checked the Session State Service status through PowerShell script Get-SPSessionStateService

In my case it returned False

To resolve this problem is easy, run PowerShell script: Enable-SPSessionStateService –DefaultProvision

And now, if we check the web.config file, the “Session” module is added there.
<add name="Session" type="System.Web.SessionState.SessionStateModule" />

The error should now go away and Session State should be enabled for your web application.