CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Peter's Gekko

public Blog MyNotepad : Imho { }

The scope of the session object (where have my objects gone ?)

You can use the session object to store things you need in other places of your web-app. With the many assemblies which make an app it is sometimes a little puzzling where your session objects can be reached and where they are unavailable. When your code enters another assembly (like a classlib) your objects will be there. But when your app enters a page in another webapp (that is another virtual IIS directory) your session objects are unreachable. It does make sense when I start thinking about it (imagine some other alien app fiddling with your session objects..). But it had me pulling my hair for some time. (Yes you may laugh..)

When you want to exchange data with another webapplication you can use a cookie. The bad thing about that is that it takes some more effort to administer those (don't forget to remove), cookies can only store string values and cookies travel over the wire from and to the client. But they do work.

Peter

 



Comments

James D. Beine said:

Hi Peter!

You can use Application (objects) much the same way as Session (objects) when you need to share information between two apps. And you get isolation at the Application Pool Level if I am right.

Jamie
# April 7, 2004 10:33 AM

Peter said:

Gentlemen, thanks for your ideas.

James, Afaik (have not tested this in detail) the application object does not cross application boundaries. Even worse : in a webfarm or webforest scenario there are multiple application objects. One per application instance. If the next request of an app is handled by another application instance the app will not see what a former request has stored in the application object. Even if it is still in the same app.

Kevin, nice workaround but to use it you have to put all the apps in one virtual dir. Given the situation this is not an option. Besides that it puts "to much hierarchy" in the organization, I like my apps to jump around in the web (not tree) of available apps on my server.
# April 8, 2004 2:37 AM

Jeff Varszegi said:

Isn't there a setting you can use to store the session state in SQL Server? This should let you access the session state across multiple websites on multiple machines in a farm. I've never done it, but it is supposed to be possible-- it's one of the major advances in ASP.NET and IIS 6.
# April 8, 2004 9:52 AM

Peter said:

There are 3 places where asp.net can store the session objects
1. In server memory (default)
2. On a dedicated state server
3. In a sql server database

The latter would make it theoritcally possible to inspect a session object belonging to another application. Or even an other user. I don't think asp.net security will let you through.

My misled hope was to share the session object between apps. That can't be done you need cookies for that. Blog on that later.
# April 11, 2004 2:51 PM

James D. Beine said:

Thanks Peter,

I did not know that there was isolation between apps in a single pool (with respect to the application object).

Worthy of additional study.

Thanks again.
# April 13, 2004 6:01 PM

James D. Beine said:

Peter, this could be done with a webservice for the purpose of creating a SAL(Session Abstraction Layer) you could create a service that your apps could use as a stack of sorts.

Just an idea. May not be practical from any sense but if you pushed your session data to a thrid party app (such as a web service) then your other apps could subscribe to that information.

Jamie
# April 13, 2004 6:06 PM

Peter van Ooijen said:

hi James, a webservice would be a good idea. But somewhat of an overkill. A cookie post will follow.
# April 16, 2004 2:12 AM

Please enter your name said:

Comments Please enter a comment
# December 10, 2004 7:06 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Check out Devlicio.us!

This Blog

Syndication

News