Why does session not work in my Composite C1?

Topics: General, Troubleshooting
Jun 12, 2011 at 12:57 AM
Edited Jun 12, 2011 at 1:20 AM


I have enabled sessiom in my web.config using the following tags:

		<sessionState mode="InProc" cookieless="AutoDetect" timeout="30"/>
		<trust level="Full" originUrl=""/>
		<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" enableSessionState="true" asyncTimeout="900" enableViewState="true" enableViewStateMac="true" validateRequest="true"
For the life of me I cannot understand why HttpContext.Current.Session is null whenever I try and access or set a Session variable.
<add name="Session" type="System.Web.SessionState.SessionStateModule"/> I also put this into the httpModules section.
Also when I put a breakpoint into Session_Start in global.asax it does not get hit.
NB: This is when being used in my VS IDE.
Am I missing something fundemental re the usage of Composite? Sessionwise...
Jun 14, 2011 at 8:16 AM
Edited Jun 14, 2011 at 8:16 AM

Where do you try to access your session from? Usercontrol, a generic handler or... ? If its the latter, you need to make sure your class implements IRequiresSessionState as well.

Specifies that the target HTTP handler requires read and write access to session-state values. This is a marker interface and has no methods.

Also, Session_Start in global.asax will not be fired until the first time you actually put something in the session, before that session is not considered to have started.

Jun 16, 2011 at 4:45 PM

Hi BurningIce

Thank you for your response.

I am accessing session from a UserControl - I use HttpContext.Current.Session rather than this.Session for no reason in particular. However, this.Session also returns null.

Thank you for pointing out the Session_Start details ... This area is never hit even when my Code tests Session to see if it is null.

It is as if enableSessionState="false".

Or, that a different Web.Config from the one in the root is being used.

Any ideas?


Jun 16, 2011 at 7:12 PM
Edited Jun 16, 2011 at 7:13 PM

You can always test what the actual value is like this

var section = (SessionStateSection)WebConfigurationManager.GetWebApplicationSection("system.web/sessionState");

throw new Exception(section.Mode.ToString());
Jun 17, 2011 at 1:59 PM

Hi burningice

The test gave the right answer - InProc was setup correctly.

However, your first post regarding generic handlers got me thinking.

Whilst the problem was manifesting in the UserControl in question this control was being loaded into a Composite page.

So, in the file CompositeC1Page.cs in the Core library it was necessary to add ", System.Web.SessionState.IRequiresSessionState" as an inheritance clause.

Immediately this was added and I ran my project Session was no longer null :)


Jun 17, 2011 at 5:04 PM

wow... thats new to me! of all the years i've worked with asp.net i've always had the assumption that classes inheriting from System.Web.UI.Page implicitly implements IRequiresSessionState as well! thats at least how it use to work. I'll digg further into this and see what can be causing this behavior.