HttpSessionState is not initialized.

Apr 23, 2008 at 12:30 PM
Hi,

I get HttpSessionState is not initialized. sometimes when using StateValue<T> even if the session has not timed out. I can't figure out why this is happening. I'm using forms authentication. Any ideas?

Br Christoffer
Apr 24, 2008 at 5:08 PM
Does anyone have a some ideas how I could go ahead with this? Any links or something how the statevalue contra session handling is handled? This is really strange :(. /Christoffer
Coordinator
Apr 24, 2008 at 10:57 PM
You may want to look at these two threads:

I hope those help,
Michael Puleio - patterns & practices
Bloghttp://blogs.msdn.com/mpuleio/
Apr 25, 2008 at 9:26 AM
FWIW,

I have found that from time to time the variables I have 'saved' via StateValue<T> are 'reset'. By reset I mean said variable is stored successfully and I can retrieve and use it, yet in a later part of the same process they no longer exist.

Again, I do not believe the session has timed out because timewise this happens within a minute?

It also seems intermittant and I haven't been able to work out how to track down the cause. I'm also unable to consistently reproduce it.

Any suggestions welcomed.

L
Apr 25, 2008 at 12:30 PM

LeonK wrote:
FWIW,

I have found that from time to time the variables I have 'saved' via StateValue<T> are 'reset'. By reset I mean said variable is stored successfully and I can retrieve and use it, yet in a later part of the same process they no longer exist.

Again, I do not believe the session has timed out because timewise this happens within a minute?

It also seems intermittant and I haven't been able to work out how to track down the cause. I'm also unable to consistently reproduce it.

Any suggestions welcomed.

L


I couldn't have said it better myself. This is exactly the same issue I'm facing and it's a very strange behaviour.

In my case I have a object that handles connection etz to the database this due to brown scenario and we don't want to reinvent the wheel. But as you say when it's "reset" we can't get hold of the object and the application gets fubar.
Apr 25, 2008 at 2:07 PM
For some reason in HttpSessionState.cs this Properry returns null. The internal _session field is null and also System.Web.HttpContext.Current.Session

What could possible make the session go down? Is there anything else but the Timeout in web.config?

protected System.Web.SessionState.HttpSessionState Session
{
get
{
System.Web.SessionState.HttpSessionState result = _session ?? System.Web.HttpContext.Current.Session;
if (result == null)
{
throw new Exception(Resources.HttpSessionStateNotInitialized);
}
return result;
}
}
Apr 29, 2008 at 9:08 AM
Hi I found that we have done our own SessionStateBindingStrategy!

public class SessionStateBindingStrategy : BuilderStrategy
{
/// <summary>
/// Inspect the object for <see cref="BuilderStrategy"/> and set the object field values accordingly.
/// </summary>
public override object BuildUp(IBuilderContext context, Type typeToBuild, object existing, string idToBuild)
{
// Get the session state
ISessionStateLocatorService sessionLocator =
context.Locator.Get<ISessionStateLocatorService>(
new DependencyResolutionLocatorKey(typeof(ISessionStateLocatorService), null));
if (sessionLocator != null)
{
IHttpSessionState sessionState = sessionLocator.GetSessionState();
// Use non public instance fields!
foreach (FieldInfo fieldInfo in typeToBuild.GetFields(BindingFlags.Instance | BindingFlags.NonPublic))
{
SetFieldValue(existing, fieldInfo, sessionState);
}
}
return base.BuildUp(context, typeToBuild, existing, idToBuild);
}

This means that we have stated private StateValues. Could this be the root of the strange behaviour. I have fixed so I can debug this and stops in HttpSessionState.cs. The session is GONE :((( and I have no clue how to find the real cause of this. ANY suggestions or ideas would be appreciated!!!

Br Christoffer
Apr 29, 2008 at 9:22 AM

syggen wrote:

This means that we have stated private StateValues. Could this be the root of the strange behaviour. I have fixed so I can debug this and stops in HttpSessionState.cs. The session is GONE :((( and I have no clue how to find the real cause of this. ANY suggestions or ideas would be appreciated!!!

Br Christoffer


I changed to use the WCSF SessionStateBindingStrategy and changed all StateValues to be public. I still get the HttpSessionState is not initialized :(.
Apr 29, 2008 at 9:47 AM
Did you enable sessionstate in your web.config file?

<sessionState mode="InProc" timeout="60"/>
Apr 29, 2008 at 10:01 AM
HAAHAHAHAAH

Hi guys!!!!

I'm happy to tell you that when I was converting all StateValues to use Session directly i saw that the timeout was set to 1 minut. I will change this 20 minutes and hope that I get rid of my problems ;P
May 17, 2008 at 4:57 AM
Can you give me an example of how to use StateValue<T> with ISessionStateLocatorService or IHttpContextLocatorService (session)?

WCSF gives us Shell Module. We added our own business modules. We want to share values across this modules via Session. How do we share value between modules via session.

Do I have to implement IHttpContextLocatorService in each Controller?

i.e. ShellController.cs

private _httpContextLocatorService;

public ShellController([ServiceDependency]IHttpContextLocatorService httpContextLocatorService)
{
    _httpContextLocatorService = httpContextLocatorService;
}

public IHttpContext Context
{
   return _httpContextLocatorService.GetCurrentContext();
}

UserController.cs

private _httpContextLocatorService;

public ShellController([ServiceDependency]IHttpContextLocatorService httpContextLocatorService)
{
    _httpContextLocatorService = httpContextLocatorService;
}

public IHttpContext Context
{
   return _httpContextLocatorService.GetCurrentContext();
}

OrderController.cs

private _httpContextLocatorService;

public ShellController([ServiceDependency]IHttpContextLocatorService httpContextLocatorService)
{
    _httpContextLocatorService = httpContextLocatorService;
}

public IHttpContext Context
{
   return _httpContextLocatorService.GetCurrentContext();
}

Is this right? Or once I implement it in ShellController.cs, is there any other way to access in other controller.