Note: This article was originally published in 2010. Some steps, commands, or software versions may have changed. Check the current .Net documentation for the latest information.

In this step-by-step guide, you’ll learn enable session in a sharepoint 2010 application page?. .

Prerequisites

Before you begin, make sure you have:

  • Visual Studio or .NET CLI installed
  • .NET Framework or .NET Core SDK
  • Basic C# programming knowledge

How to enable Session State in SharePoint 2010

So as a developer you may have come across the need to use the Session object along the way. What you’ve probably noticed is that you get an error message that indicates you should enable session state as well as configure your http session module for sessions:

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 web.config

In order to resolve this you should make two entries into your web.config (in this case the one located under: C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14TEMPLATELAYOUTS) file and run an SP command:

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

if you don’t have the pages directive you can add it the following one under the -> <system.web> nodes:

This is found under the -> <system.web> nodes

The second is to ensure that you have enabled Session as an http module by addint the following lines under the -> <system.web> nodes:

The third step is to run the following SP command line:

Enable-SPSessionStateService –DefaultProvision

This instruction needs to be executed in the SP 2010 Power shell otherwise it won’t work. Be sure to run the power-shell as an administrator otherwise it won’t work.

For more information please visit the references below

References:

Summary

You’ve successfully learned enable session in a sharepoint 2010 application page?. If you run into any issues, double-check the prerequisites and ensure your .Net environment is properly configured.