Solved

Asp.Net Static Variable Question

Posted on 2011-09-06
5
355 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASCX file or a newer alternative? 1 34
How to reference objects of the calling class without passing them as parameters 29 171
Video Player 11 23
C# Gridview 1 29
Running classic asp applications under Windows Server 2008 R2 (x64) and IIS 7 is not as easy as one may think. It took me a while to figure it out while getting error 8002801d a few times. After you install the OS you will need to install the fol…
A phishing scam that claims a recipient’s credit card details have been “suspended” is the latest trend in spoof emails.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

786 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