When you want to use Session object inside C# or VB.NET Code in SharePoint pages and Web Parts,
you receive such error message:
Session state can only be used when enableSessionState is set to true, either in a configuration file
or in the Page directive.
Many people wrote 3 steps, that you need to do for enabling Session State inside SharePoint:
1. Change enableSessionState in page section in system.web inside web.config for your Web Application.
<pages enableSessionState="true" enableViewState="true" enableViewStateMac="true"
validateRequest="false"
pageParserFilterType="Microsoft.SharePoint.ApplicationRuntime.SPPageParserFilter,
Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
asyncTimeout="7">
2. Add Session Module in modules section in system.web inside web.config for your Web Application
<modules runAllManagedModulesForAllRequests="true">
<remove name="Session" />
<add name="Session" type="System.Web.SessionState.SessionStateModule" preCondition="" />
<modules>
3. Start Session State service application inside
Central Administration -> Application Mangement -> Manage Service Application
But some times is not enough and you need to add some additional lines in web.config file.
Open web.config file and locate <PageParserPaths> tag inside <SharePoint> <SafeMode> tag.
Inside this PageParserPaths tags add two lines for each page that use Session object:
<PageParserPath VirtualPath="/Site/Pages/Page1.aspx" CompilationMode="Always" AllowServerSideScript="true" />
<PageParserPath VirtualPath="Page1.aspx" CompilationMode="Always" AllowServerSideScript="true" />
In first line attribute VirtualPath write server relative url to your page (include site name),
in second line attribute VirtualPath write only page name and extension.
I hope this post help to you solve problem with Session object inside Visial Stidio 2010.
Enjoy