Tuesday, April 5, 2011

ASP.Net Session State in SharePoint 2010

Although we have State Service service application running in our SharePoint farm, it doesn’t mean that it directly support ASP.Net session state. State service is more towards facilitating session information for office internal components such as InfoPath form services, Visio services, etc.…

If we need to maintain ASP.Net session state for SharePoint 2010 pages we have to enable it manually. Recently I wanted to enable ASP.Net sessions in one of my Visual Web Parts.

There are two ways that you can use to enable ASP.Net sessions.

1] Using PowerShell command

Use following command to enable the ASP.Net session state service

Enable-SPSessionStateService –DefaultProvision

After that you can see a new service application “SharePoint Server ASP.Net Session State Service” running in the service application section

image

that’s all !!

2] Session State Managed module using IIS Manager

You have to use this method if you are using SharePoint Foundation. You can use this for SharePoint 2010 Server versions also. but you will not get a separate service application. For SharePoint 2010 server versions, recommended best practice is to use the 1st method which is to use PowerShell command.

First we have to modify few settings in the web.config file of the respective SharePoint 2010 web application

<pages enableSessionState="true" …… >

Then add session state module within system.web section

<httpModules>
<
add name="Session" type="System.Web.SessionState.SessionStateModule" />
</
httpModules>

After that we have to add the Session state module in IIS7 for the web application.

Go to IIS Manager, select the relevant SharePoint web application and open the Modules section

image

Inside the modules section click on Add managed module link to add the Session State module

image

Input a name for the module and select following for the module type from the dropdown


System.Web.SessionState.SessionStateModule,System.Web,Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

image

That’s it !!. now you can use ASP.Net Sessions in your SharePoint 2010 pages

1 comment:

Petter Marry said...
This comment has been removed by the author.