Access to session data in filters

May 25, 2010 at 6:49 PM
Edited May 25, 2010 at 6:50 PM


I'm trying to create a filter which parses CSS to find placeholders which I replace with values for my app. One of those placeholders is the user's current language preference. So, I need access to session data so I can see who the currently logged in user is.

The issue is that the Combres HTTP Handler does not implement the IReadOnlySessionState interface.

The only other option I have is to wrap the combers handler with my class which implements the interface. However, there are a bunch of sealed internal classes preventing me from doing this.

Is it possible to either implement IReadOnlySessionState on the Combres Http Handler or make all the associated classes not internal sealed.

Thanks for all your hard work. Combres is awesome!


May 26, 2010 at 4:46 PM

Hi Nate,

It would take more than just implementing IReadOnlySessionState to support your scenario :).  Under normal configuration settings, Combres will generate the content for a resource set once, running all filters on it, and cache the result for subsequent requests.  Furthermore, the URL generated for the set and the client cache headers generated by Combres will tell the browser to cache the local copy of the resource set's content.  Therefore, filters that work based on different language preferences stored the session state won't work at all (i.e. only the preference of the 1st request to the resource set will be used - until the cache of browser & server is expired).

A generic solution would need to allow users to tweak the generated URL and server-side cache key of Combres via code.  I've already implemented such a generic solution in this changeset  You can check out the example in the MvcSample project, which I mimic the scenario you described with the custom  implementations of ICacheVaryProvider and ICacheVaryStateReceiver (defined in SampleCommon library project).  You might also want to read the code documentation of these 2 interfaces to know how to incorporate this feature into your application.

Take a look and let me know if this meets your need.