Modify the ASP.NET Session during debug?

1.2k views Asked by At

Is it possible to modify values, keys or even clear the Session during debugging of an ASP.NET page?
I tried the following in the Immediate Window (in the presented order), but nothing changed the Session object:

Session.Clear()
Expression has been evaluated and has no value

Session.Keys
{System.Collections.Specialized.NameObjectCollectionBase.KeysCollection}
    Count: 12

Session.Clear()
Expression has been evaluated and has no value

Session.Keys[0]
"user_id"

Session.Abandon()
Expression has been evaluated and has no value

Session["user_id"]
3

Edit: OK, it looks like I can sometimes change it. This is very puzzling. If someone knows why it's sometimes failing, I'd appreciate having that knowledge.

1

There are 1 answers

0
Protector one On BEST ANSWER

You can change the Session with the Intermediate and Command Windows in debug mode.
Just make sure you don't have any code (e.g., the getter of a property, a rogue Trace Point that prints a "message" like {HttpContext.Current.Session["some_key"] = [some value];}, etc.), that resets the values after you make the changes.

(Lesson learned.)