?
Solved

Asp.Net Static Variable Question

Posted on 2011-09-06
5
Medium Priority
?
376 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Loops Section Overview
Suggested Courses
Course of the Month17 days, 5 hours left to enroll

864 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