Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing Selected Session items (VB ASP.NET)

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.

like image 669
Jamie Hartnoll Avatar asked Apr 30 '26 06:04

Jamie Hartnoll


1 Answers

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.

like image 80
3Dave Avatar answered May 02 '26 22:05

3Dave



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!