Static interference variable ASP.net?

I am new to web development and ASP.net but I was wondering about the following question:

If I declare a static variable on a web page and multiple users access the same page at the same time. Is this a static variable unique to each user, or will it interfere with different users?

thanks

+6
source share
2 answers

Yes, this will interfere between users and between concurrent requests of one user. Avoid static fields in ASP.NET (and most other developments) if you are not sure what you are doing.

Consider using session state for what you are doing here, or something as part of the request itself (form data, cookie, etc.).

+7
source

Is this static variable unique to each user.

Not.

will it interfere with other users?

Yes.

You would like to use some other persistence tools such as session state, caching , etc.

Some people use the [ThreadStatic] attribute for fields in ASP.NET, so it is unique to each user, but it is dangerous and should not be done. Avoid this at all costs. I only pick it up if someone else recommends it.

+2
source

Source: https://habr.com/ru/post/920122/


All Articles