Hello All,
It's well known fact that static variable cannot be used in Web Application as it remains static through out application.But,is there any scenario where static variable can be used in Web Application to achieve the functionality?
Thanks
Hello All,
It's well known fact that static variable cannot be used in Web Application as it remains static through out application.But,is there any scenario where static variable can be used in Web Application to achieve the functionality?
Thanks
You can store your static information in a number of places...
(Or am I misunderstanding the question?)
You don't mention what web framework you are using, but if you are using ASP.Net, you can assign objects to the Application object or the Session object, which will hold information across the application between requests, and across all requests from an individual user respectively.
If you are asking in a general way, and I suspect you are as this is marked subjective+discussion, then you can try using a cookie to hold the variable across all requests for a user.
As for holding some value for all users, you should have a look at the web framework you are using. You have options such as storing something in a file that is accessible at each request, through to storing something in the equivalent of the Application object of ASP.Net.
I'm sorry if I'm being too pragmatic here, but it's late where I live :).
I'm not sure if I understand the question, but there are cases in which using a static variable in a web application is perfectly fine, if one understands the implications. For instance, a common usage in .NET web applications using NHibernate and the "session-per-request" model is to keep a static instance of an ISessionFactory around to create new NHibernate sessions. This is useful since session factories are very heavy objects and generally take a lot of resources to create.