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 1Syntax 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 :)

 

Comments

Popular posts from this blog

Hide Ribbon on SharePoint 2013 using CSS

Get Comment Count in SharePoint

Configure external site as content sources in sharepoint search