Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

2 Answers 2

up vote 5 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
1  
This solution works 100%, verified. –  Frederik P. Apr 26 '12 at 10:36

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

Your Answer

 
discard

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.