What is the difference between Session.Abandon() and Session.Clear()

前端 未结 10 950
陌清茗
陌清茗 2020-11-28 03:36

What is the difference between destroying a session and removing its values? Can you please provide an example demonstrating this?

I searched for this question, but

10条回答
  •  遥遥无期
    2020-11-28 03:47

    This is sort of covered by the various responses above, but the first time I read this article I missed an important fact, which led to a minor bug in my code...

    Session.Clear() will CLEAR the values of all the keys but will NOT cause the session end event to fire.

    Session.Abandon() will NOT clear the values on the current request. IF another page is requested, the values will be gone for that one. However, abandon WILL throw the event.

    So, in my case (and perhaps in yours?), I needed Clear() followed by Abandon().

提交回复
热议问题