Solved

Asp.Net Static Variable Question

Posted on 2011-09-06
5
359 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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!
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

729 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