views:

596

answers:

2

In ASP.NET 3.5, is it possible to iterate through all of the session objects (not the objects within the current session, but all sessions across all users) so that their collection contents can be manipulated (i.e. one collection item removed from all active sessions)?

And if so, does this work with ASP.NET State Service (accessing all sessions created by all web servers that are sharing the same state service, all from one web server)?

+1  A: 

This answer to a question I asked about removing a session from another session may be helpful to you. I haven't tried it and you'd need to extend it, but it appears possible to access the container for all sessions using reflection.

tvanfosson
Does that technique remove items from the underlying session store? Does it remove them from SQL Server if stored there, or from the state server?
John Saunders
It only applies to the InProc session, which would only be useful on a single server. Doing it from SQL server ought to be much easier but I haven't actually looked at the schema to know whether it's possible to access a particular item. I typically use InProc since I don't store much and my applications are small enough for a single server.
tvanfosson
Thanks, but you could also put the Session into a new collection and put that into the Application collection. I need to update on behalf of all servers using the state server.
stimpy77
Perhaps it would be better to explain what you're trying to accomplish. Using reflection to dig into sessions has a "smell" to it. Perhaps it would be better to create a synchronization service that all sessions would check on each request to see if they should do something to their own collection.
tvanfosson
+1  A: 

I think the only answer I've come up with is: If you're working with a single box, you can put the sessions into a collection that is stored in the Application collection, and remove each session when each session ends. But for making global session updates to a shared state server, credit goes to tvanfosson's comment under one of the other answers: SQL Server is the only reasonably viable option, outside of using a third party or alternate state server that enables this feature via network sockets.

stimpy77