C# Clear Session

前端 未结 3 766
轮回少年
轮回少年 2020-12-02 12:18

Question #1

I want to know when am I supposed to use:

Session.Abandon() // When I use this during tracing and after calling i

3条回答
  •  孤城傲影
    2020-12-02 12:59

    The other big difference is Abandon does not remove items immediately, but when it does then cleanup it does a loop over session items to check for STA COM objects it needs to handle specially. And this can be a problem.

    Under high load it's possible for two (or more) requests to make it to the server for the same session (that is two requests with the same session cookie). Their execution will be serialized, but since Abandon doesn't clear out the items synchronously but rather sets a flag it's possible for both requests to run, and both requests to schedule a work item to clear out session "later". Both these work items can then run at the same time, and both are checking the session objects, and both are clearing out the array of objects, and what happens when you have two things iterating over a list and changing it?? Boom! And since this happens in a queueuserworkitem callback and is NOT done in a try/catch (thanks MS), it will bring down your entire app domain. Been there.

提交回复
热议问题