Solved

Asp.Net Static Variable Question

Posted on 2011-09-06
5
347 Views
Last Modified: 2012-08-13
We are currently in a situation where our server is crashing during high load on the server, and we have just noticed that our web developer is storing state for each client connection in static variables on each page of the website.  We are under the impression that this could be a very bad idea, do all clients who connect to our website share those variables since their static?  This is really bad because if thats the case, we might get mixed information and it could be crashing our server, but we are not experts at this.

To give an example, we have a master page file that has a static variable stating what the current web page is loaded is etc.  Is this an issue with asp.net?
0
Comment
Question by:recruitit
  • 2
  • 2
5 Comments
 
LVL 10

Expert Comment

by:oxyoo
ID: 36487050
I believe these two links describes your problem and why you should not use statics:

http://support.microsoft.com/?id=893666

http://www.foliotek.com/devblog/avoid-static-variables-in-asp-net/

0
 

Author Comment

by:recruitit
ID: 36487080
Not to be rude but I came here for an answer, not for links to read as I can get plenty of those from a google search, I am looking for someone with experience in this matter.
0
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36487083
You are right. static is not advisable in asp.net application. http://www.foliotek.com/devblog/avoid-static-variables-in-asp-net/

You can use ViewState, Hidden fields, Session variable, Cache, Application  whatever is applicable in your case. If possible try to use querystring if you are passing information from one page to another page.
0
 
LVL 16

Accepted Solution

by:
Easwaran Paramasivam earned 500 total points
ID: 36487099
We faced same kind of issue in one of our project.
We stored header image and footer image detail in static.

User1 chose some header and footer, the fields are stored correctly.
User2 chose nothing. But as it is stored in static, User2 got header and footer as User1 chose.

We resolved using Session variables as it is user based. It resolved our issue.

0
 
LVL 10

Expert Comment

by:oxyoo
ID: 36487292
@recruitit That's ok, be rude all you want. The reason I posted the links are twofold, first they describes the same problem you're having second it presents a solution in much more detail and better than I could have done here. Also, if all you wanted was an answer it was in my "you should not use statics" sentence.

I did not mean to suggest, by posting those links, that you are incapable of using google, bing, or duckduckgo.


0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now