1

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?

1
  • 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 session Commented Jul 25, 2015 at 3:00

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for confirming my worst suspicions. Will help to avoid a lot of potential pain in the neck
0

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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.