Enable session state in SharePoint


Hi,

I was trying to use the Session[“key“] code in SharePoint. I got the following exception: “Session state can only be used when enableSessionState is set to true, either……………..”.

After facing this error, I found that by Default the Session State is Disabled in SharePoint. If you look at the Web.Config the you will see that as below.

<pages enableSessionState="false"

You can enable it there. Else you can Enable this at the Page Level. But I recommend you being a SharePoint guy you must rely upon the SharePoint Power shell command:

“Enable-SPSessionStateService –DefaultProvision”

It should not be necessary to edit the web.config file after running Enable-SPSessionStateService. Additional information about enabling session state:

Syntax 1 Syntax 2
Enable-SPSessionStateService
-DefaultProvision
Enable-SPSessionStateService
-DatabaseName <String>
[-DatabaseServer <String>]
[-DatabaseCredentials <PSCredential>]

Additional parameters are not discussed here; use Get-Help Enable-SPSessionStateService –full for more information.

The Enable-SPSessionStateService cmdlet creates a session state database, installs the ASP.NET session state schema, and updates the Web.config files on the farm to turn on the session state service.

If the DefaultProvision form of the command is used, all default settings are used. These are:

  • DatabaseName = “SessionStateService_<GUID>”
  • DatabaseServer = the same database server as the SharePoint 2010 configuration database
  • DatabaseCredentials = Integrated Windows Authentication

Happy SharePointing 🙂

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s