GlobalContext, ClientContext, LocalContext in ASP.Net land

GlobalContext, ClientContext, LocalContext in ASP.Net land

Old forum URL: forums.lhotka.net/forums/t/11600.aspx


joemorin73 posted on Wednesday, September 26, 2012

I have two questions:

  1. In the ASP.Net scope of things, GlobalContext, ClientContext, LocalContext appear to be the same.  The three store to the current HttpContext Items collection and are limited to the users session.  Is this correct?
  2. Is there a an API like context that would store to the application domain?  (either Cache or Application in ASP.Net)  I know I can directly access these on the ASP.Net, but I wouldn't mind a preexisting api so it can operate in both an ASP and non ASP environment.

RockfordLhotka replied on Wednesday, September 26, 2012

In a 2-tier web deployment you are correct.

In a 3-tier web deployment, where the web server communicates with an app server, then GlobalContext and ClientContext obviously provide different capabilities from LocalContext.

In any case, web and app servers are stateless, so once the client request processing is done, everything in memory on the server(s) goes away. That includes all three context dictionaries.

If you need to maintain state on your web server between client requests, you'll need to use standard ASP.NET state management features, such as Session. Of course there are a lot of downsides to maintaining state between client requests, and most web experts would strongly discourage such an approach. At the same time, people _do_ use Session, and I'm sure they sleep OK at night :)

joemorin73 replied on Wednesday, September 26, 2012

This appears to be a problem.  It seems that the ClientContext seem to live past the page life.  IE, living as long as the session.

JonnyBee replied on Wednesday, September 26, 2012

You must make sure that Csla.Web.dll is deployed to the website. 

RockfordLhotka replied on Wednesday, September 26, 2012

The default context provider uses thread local storage, which is great for pure .NET environments. This will NOT work in an ASP.NET environment due to the way ASP.NET manages its threads.

The ASP.NET context provider (automatically used if Csla.Web.dll is in your web server's bin folder) uses HttpContext to manage all context dictionaries and the User value.

So Jonny is correct, if you have Csla.Web.dll in your bin directory then you should see the correct behavior.

joemorin73 replied on Wednesday, September 26, 2012

Interesting.  I did forget to put the Csla.Web in the Web application.  The fact that the Thread collection worked surprises me and scares me at the same time.  Ok.

That said, Csla has no API that will use Application and/or Session. Which is fine, I can have my own.

Copyright (c) Marimer LLC