Session state can only be used when enableSessionState is set to true


I have a user control using session module in ASP.NET running on SharePoint 2010.

I configured the all the session settings which are:

  • Http Module

    <httpModules>

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

    </httpModules>

  • Pages directive

<pages enableSessionState=”true” …….

  • Modules

    <modules runAllManagedModulesForAllRequests=”true”>

    <remove name=”AnonymousIdentification” />

    <remove name=”FileAuthorization” />

    <remove name=”Profile” />

    <remove name=”WebDAVModule” />
    <remove name=”Session” />

    <add name=”SPRequestModule” preCondition=”integratedMode” type=”Microsoft.SharePoint.ApplicationRuntime.SPRequestModule, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” />

    <add name=”ScriptModule” preCondition=”integratedMode” type=”System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ />

    <add name=”SharePoint14Module” preCondition=”integratedMode” />

    <add name=”StateServiceModule” type=”Microsoft.Office.Server.Administration.StateModule, Microsoft.Office.Server, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” />

    <add name=”PwaAuthentication” type=”Microsoft.Office.Project.PWA.PwaAuthenticationModule, Microsoft.Office.Project.Server.PWA, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” />

    <add name=”RSRedirectModule” type=”Microsoft.ReportingServices.SharePoint.Soap.RSRedirectModule, RSSharePointSoapProxy, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91″ />

    <add name=”PublishingHttpModule” type=”Microsoft.SharePoint.Publishing.PublishingHttpModule, Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” />

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

    </modules>

Now, the surprise…

I am able to set a value in the session , ex:

Session[“X”] = “my new value”;

But when reading the value, I got the following error:

Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive.

Solution

Add the following line IN BOLD only

<SharePoint>

<SafeMode MaxControls=”200″ CallStack=”false” DirectFileDependencies=”10″ TotalFileDependencies=”50″ AllowPageLevelTrace=”false”>

<PageParserPaths>

    <PageParserPath VirtualPath=”/*” CompilationMode=”Always” AllowServerSideScript=”true” IncludeSubFolders=”true” />

</PageParserPaths>

Advertisements

One thought on “Session state can only be used when enableSessionState is set to true

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