I am working on something which requires various session Data to be held.
I need to be able to delete certain data from the session, but not clear the whole thing.
Obviously, I can manually delete session items with
Session.Remove("itemName")
My question is, is it possible to do something like set a prefix to all session variables and then delete all variables with that prefix?
useData = session("snippet_theData")
and then something that does
Session.Remove("snippet_*")
...rather than having to manually remove each item individually.
The most direct way would be to iterate through the session collection and use either a simple string match (string.StartsWith) or a regular expression (overkill if your IDs are really as simple as snippet_), and either use Session.Remove() to remove the item, or set its value to null or an empty string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With