开发者

How can I throw an Exception if Session is written to in ReadOnly mode?

开发者 https://www.devze.com 2023-01-15 06:20 出处:网络
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 re

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 t开发者_运维问答here. 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


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.


I ended up implementing my own SessionStateModule to achieve what I needed. See this thread for more info: I just discovered why all ASP.Net websites are slow, and I am trying to work out what to do about it

0

精彩评论

暂无评论...
验证码 换一张
取 消