ASP.NET static variable, please use caution

zhaozj2021-02-16  70

In C # / VB.NET, the static variable is indeed very attractive, and the access of the static variable is even more unmectized, and the value of static variable can be updated any.

If it is that, use static variables to be qualified for session and Application, even web.config. However, after research

This approach is very dangerous. First, the static variable is in memory, but it is a single shared memory. ASP.NET is not a stand-alone version, and the client's access is multithreaded.

So once a user changes a variable, then all users have changed. Second, the survival of static variables is limited. When IIS's memory takes up more than a certain range, the system will automatically clean up the session, the specific mechanism is also

Unclear, but static variables may be emptied. Many people coming from Windows may think more of static, but I have found that the web is different from Windows. If Static can get all this, That Microsoft still wants to engage in SESSION, so complex, but also SESSION does not exist in cookie

, Session encryption? If you need, use the Application object, you can also use configuration or use session. In short, don't use Static, unless you know what you are doing.

转载请注明原文地址:https://www.9cbs.com/read-12456.html

New Post(0)