This might be a silly question, but if I create a class in ASP.NET/VB.NET application with a shared property (one accessible just by class name and not required class instantiation) and one user, currently logged in would set that property - would this shared value be accessible to another user of the same ASP.NET application using it at the same time, or would the value be confined for the user who set it?
-
Unless I am misunderstanding this question, the anser is: NO, NOT SHARED! Eesh, at a minimum folks should take the "Yes" answers here with a grain of salt, requiring more research. "That's just not how it works. ASP.Net page class instances are nearly always created and destroyed again in well under one second..." "The ASP.Net runtime creates a new instance of your class for every request." Reference: Accessing public class variables in asp.net without sessionJayRO-GreyBeard– JayRO-GreyBeard2015-07-25 03:00:17 +00:00Commented Jul 25, 2015 at 3:00
Add a comment
|
2 Answers
Everyone. The class is loaded once by the server process and stays in memory to service all requests. So the shared property would show the same value for all page requests.
Had this problem with a website, the creator used a shared database object and users would end up getting each others search results.
1 Comment
Comfortably Numb
Thank you for confirming my worst suspicions. Will help to avoid a lot of potential pain in the neck
Silly question since OOP does not have user concept :)
Silly answer: shared value will be accessible to another user of the same ASP.NET application using it at the same time.
1 Comment
Chris
It would be quite possible for you to create a web server where each distinct user has their own app domain so its not as silly a question as you think. The question is only silly if you know it doesn't work like this.