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

I got the following error when I try to load aspx page which is loading user control (ascx)
I'm trying to set a session variable in my user control and I get the below error over that step.

I did page enabled =true on my aspx page, web.config and checked IIS the ASP.Net session is enabled. What else can be checked.

I have like this in my web.config file -

"<pages enableSessionState="true" enableViewState="true" enableViewStateMac="true" validateRequest="false" clientIDMode="AutoID" pageParserFilterType="Microsoft.SharePoint.ApplicationRuntime.SPPageParserFilter, Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" asyncTimeout="7">"


Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the <configuration>\<system.web>\<httpModules> section in the application configuration.
Who is Participating?
Rainer JeschorConnect With a Mentor Commented:
this is true for "normal" ASP.NET applications, but not recommended for SharePoint - especially not for SharePoint 2013!

First of all in SharePoint your normally have multiple Web Frontend Servers - therefore InProc mode should never be used.

Second, SharePoint has builtin its SessionState Servivce. To Enable Session State just open the SharePoint Management Powershell and run:
Enable-SPSessionStateService -DefaultProvision

This will create everything you need and also sets the appropriate entries in the web.config.

General SessionStateService configuration through Powershell commandlets:

ShareD_PointConnect With a Mentor Commented:

Add these lines in web.config with in the <system.web> section

<sessionState mode="InProc" timeout="60" cookieless="false" >
<add name="Session" type="System.Web.SessionState.SessionStateModule"/>

Hope this may helps.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.