views:

20

answers:

2

I would like to find a way to raise an exception if the Session is written to when in readonly mode. When EnableSessionState is set to "ReadOnly", values can still be put in Session, but the next request they will not be there. This seems somewhat dangerous.

One option is to create a helper class which we alway use to access session. However, this still leaves room for a developer to inadvertently use session directly, and fall into the "readonly" trap. Is there a way to create a CustomSessionStateDataStore that sits on top of the existing session code? I could not see an obvious way, and you can't inherit from System.Web.SessionState.SessionStateStoreData directly.

Thanks for any help

+1  A: 

Session state is built atop the provider model so you could create a custom session provider, I imagine.

Here's an article that discusses the provider model from a high-level view: ASP.NET 2.0 Provider Model: Introduction to the Provider Model.

And here's an article that talks about the session state providers and shows how to create your own custom provider: Session State Providers.

Scott Mitchell
Thanks for your answer Scott. I have previously looked at this, but can't see a way to get the CustomSessionProvider to leverage the built in session framework - which is what I am trying to do. Maybe writing my entire Session Mechanism is the only way to achieve this, but I was hoping for something a little less extreme!
James
A: 

I ended up implementing my own SessionStateModule to achieve what I needed. See this thread for more info: http://stackoverflow.com/questions/3629709/i-just-discovered-why-all-asp-net-websites-are-slow-and-i-am-trying-to-work-out

James