Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static Variable interference ASP.net?

Tags:

c#

asp.net

I am quite new to Web Development and ASP.net but i was wondering the following question:

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

Thanks

like image 694
cgval Avatar asked Jul 10 '12 12:07

cgval


1 Answers

Yes, it will interfere between users, and between concurrent requests by a single user. Avoid static fields in ASP.NET (and most other development) unless you are very sure about 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).

like image 94
Marc Gravell Avatar answered Sep 28 '22 17:09

Marc Gravell