SharePoint 2010 – Enable Session State in SharePoint 2010

20 ביוני 2011

אין תגובות

When you want to use Session object inside C# or VB.NET Code in SharePoint pages and Web Parts,

you receive such error message:

Session state can only be used when enableSessionState is set to true, either in a configuration file

or in the Page directive.

Many people wrote 3 steps, that you need to do for enabling Session State inside SharePoint:

1. Change enableSessionState in page section in system.web inside web.config for your Web Application.

<pages enableSessionState="true" enableViewState="true" enableViewStateMac="true"



Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c"


2. Add Session Module in modules section in system.web inside web.config for your Web Application

<modules runAllManagedModulesForAllRequests="true">

<remove name="Session" />

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


3. Start Session State service application inside

Central Administration -> Application Mangement -> Manage Service Application


But some times is not enough and you need to add some additional lines in web.config file.

Open web.config file and locate <PageParserPaths> tag inside <SharePoint> <SafeMode> tag.

Inside this PageParserPaths tags add two lines for each page that use Session object:

<PageParserPath VirtualPath="/Site/Pages/Page1.aspx" CompilationMode="Always" AllowServerSideScript="true" />

<PageParserPath VirtualPath="Page1.aspx" CompilationMode="Always" AllowServerSideScript="true" />

In first line attribute VirtualPath write server relative url to your page (include site name),

in second line attribute VirtualPath write only page name and extension.

I hope this post help to you solve problem with Session object inside Visial Stidio 2010.



הוסף תגובה
facebook linkedin twitter email

כתיבת תגובה

האימייל לא יוצג באתר. שדות החובה מסומנים *