Why does my ASP.Net static function's “context” crossover between user sessions?

后端 未结 5 1065
醉酒成梦
醉酒成梦 2020-12-16 03:58

I think I need some help understanding how static objects persist in an ASP.Net application. I have this scenario:

someFile.cs in a class library:

p         


        
5条回答
  •  一生所求
    2020-12-16 04:37

    Each request to an asp.net site comes in and is processed on it's own thread. But each of those threads belong to the same application. That means anything you mark as static is shared across all requests, and therefore also all sessions and users.

    In this case, the MyFunc function that's part of your page class is copied over top of the static Func member in A with every page_init, and so every time any user does a page_init, he's replacing the A.Func used by all requests.

提交回复
热议问题