ASP.NET or SharePoint 2010: Session variables do not work from within particular pages

in ASP.NET or SharePoint 2010:
if session variables are not working within a particular page, then it could be because:

web.config has Session set to InProc
AND the page is not explicitly set to use sessions.

Remedy 1: change web.config to have enableSession = true
OR Remedy 2: for each page where you require session variables, then set EnableSessionState to true, at the top of the page:

 <%@ Page Language="C#" AutoEventWireup="true"   
 EnableSessionState="true"   
 CodeBehind="MyPage.aspx.cs" Inherits="MyProject.Layouts.MyProject.MyPage" DynamicMasterPageFile="~masterurl/default.master" %>  

note: this is probably obvious to most ASP.NET developers, however it may help diagnose a problem!

Comments