Solved

Asp.Net Static Variable Question

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Function after success of Jquery/AJAX action 9 28
Where is this file? 3 26
Need syntax help building hyperlink 2 27
Upgrade code from VS 2010 to VS 2015 7 18
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

830 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