SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm loading a page with WebPart in it, and I get NullReferenceException in this line:

HttpContext.Current.Session["Foo"] = value;

because Session is null. The web.config under inetpub folder has

<pages enableSessionState="false" ... >

Does session bag being null is caused by this setting in web.config, or is the cause completely different?

share|improve this question
up vote 6 down vote accepted

Yes, If you want to use the session-state, you should enable it in the web.config of the webapplication.

To enable ASP.NET session state:

  1. Enter the following PowerShell command in the SharePoint 2010 Management Shell window: Enable-SPSessionStateService –DefaultProvision
    or more advanced:
    Enable-SPSessionStateService -DatabaseName [-DatabaseServer ] [-DatabaseCredentials ]
  2. On each web application for which you want to use session state, edit the web.config file and set the enableSessionState property of the pages element as follows:
    < pages enableSessionState="true"
share|improve this answer
This solution works 100%, verified. – Frederik P. Apr 26 '12 at 10:36
run Sharepoint Powershell as admin of cource – imanabidi Sep 2 '15 at 8:21

To use session state in SharePoint see Using Session State in SharePoint 2010, but think hard about if you really want to do it.

share|improve this answer
Why should I think hard about it? are there any drawbacks? – itsho Feb 16 '15 at 12:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.