سؤال

I use static class and static attribute and static function in my web Application project for transfer data between web forms but i want that the static class for each user created separate . is there such????? my point is that when a user log in, created a new static class in web application or one object from this static class for all user? please help and answer me!

هل كانت مفيدة؟

المحلول

static classes in asp.net are shared across threads and there is no direct correlation between threads and users. One user may user multiple threads to handle client side requests or multiple users may use only a single thread to handle all of their requests. This is dependent on server configuration and load.

While static methods can be used in an asp.net web application, static members (fields and properties) should be avoided. Theses underlying variable / containers are shared and one thread will over-write the values of another thread and lead to very difficult debugging scenarios.

Marking a class static requires that all methods and members be static and should generally be avoided in asp.net. I have used static classes from time to time to expose instance based objects and values external to the class. There is also the example of extension methods which are fine in asp.net as they don't contains static fields.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top