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

When IIS is not configured properly after creating SharePoint application and there are web parts or features that use session you may get the following error: Unexpected error occured: System.Web.HttpException: 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 \\ section in the application configuration.

Solution

As a solution you must register session state handler module in IIS.

  1. Open Internet Information Services manager.
  2. Move to site where problem occurred.
  3. Open modules list of this site.
  4. Add session state handler like show on the following image (click on it):
    IIS: Set session state module
  5. Click OK, recycle application pool and refresh the page.

I am not very sure why SharePoint doesn’t enable this module by default as mostly default session state module is enough.

Gunnar Peipman

Gunnar Peipman is ASP.NET, Azure and SharePoint fan, Estonian Microsoft user group leader, blogger, conference speaker, teacher, and tech maniac. Since 2008 he is Microsoft MVP specialized on ASP.NET.

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

    • August 20, 2013 at 4:27 pm
      Permalink

      Please GEEKS!,
      Would you think somebody posted this question might have even checked this funda?

      To all sufferers of this problem, I have my findings here!
      1. I could reproduce this issue in IE browser(IE10) and FIREFOX(22), though I have great settings of all enabled..etc.etc… in my local code, WHEN IE settings in Connection Tab –> LAN settings have “Use PROXY Server for Localhost…” checkbox shown as CHECKED – without a VALID PROXY server setting…

      When I uncheck this In IE, the same code with DEFAULT Session settings, runs like HORSE!!

      Doom to all GEEKS OUT THERE…

      But for common people, IT WAS GIVING NIGHTMARES TO ME, hope I could save a few out of yours!

      Peace!

    • March 26, 2014 at 5:38 pm
      Permalink

      Thank you a lot!

    • January 29, 2015 at 11:46 am
      Permalink

      Could be your skype intercepting your requests at 80 port, in Skype options uncheck
      Or Your IE has connection checked for Proxy when there is no proxy
      Or your fiddler could intercept and act as proxy, uncheck it!
      Solves the above problem, It solved mine!

      HydTechie

    • October 12, 2017 at 9:34 am
      Permalink

      Thanks Bro very useful article. it saves alot of my time and efforts.
      Thank you so much!

    Leave a Reply

    Your email address will not be published. Required fields are marked *