سؤال

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.

هل كانت مفيدة؟

المحلول

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.)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top