Enable Session in SharePoint 2010



In this article I am describing how to enable Session in SharePoint 2010. It is not the same as in SharePoint 2007. It is very important when you work with session state in your custom application.

Many people are demonstrating various ways to enable session state. But most of them are not the recommended practices. Here I am showing the most recommended method for SharePoint 2010 using two services related to session state that have similar names but are separate and have different purposes and uses.

  1. ASP.NET session state may be used in SharePoint 2010 pages. This service is automatically disabled in normal installations of SharePoint 2010. It has to be enabled manually. This is the service that uses when we develop custom applications with session state.
     
  2. The State Service service application is used for Office internal components such as InfoPath Forms Services and Visio Services. This service is automatically enabled in typical installations of SharePoint 2010 and is not related to ASP.NET session state.

To enable ASP.NET session state:
  1. As a first step you have to enable the following service

    ASP.Net State Service
     
  2. For doing that you have to type services.msc in run
  3. Then start the service as shown

    Session1.gif
     
  4. Enter the following PowerShell command in the SharePoint 2010 Management Shell window:

    Enable-SPSessionStateService –DefaultProvision

    Session2.gif
     
  5. On each web application for which you want to use session state, open the web.config file and set the enableSessionState property of the pages element to true

    <pages enableSessionState="true">

    Session3.gif
     
  6. Now go to your SharePoint central Administration ->Application management
  7. Under Service Applications click on Manage service applications
  8. Now you can find out the SharePoint Server ASP.Net State Service is started now

    Session4.gif