I have written a simple webapp in asp net. The first time I go through the program Everything w开发者_如何转开发orks fine, but if I go there again it uses that variables from my last session.
So the questions are
Is there anyway to correct this?
Does it have something to do with how I make my public variables?
Could I store the variables as cookies, then delete them when the page closes?
This is how I make my public variables:
static class vars
{
public static List<string> directory_names = new List<string>();
public static List<string> directory = new List<string>();
public static int numvar = 0;
//There are more but they all are made the same way
}
Any Ideas are welcome.
Thanks, Adam
You should avoid static as it means the variable will be the same for every user connected (plus you will probably face threading issue).
Here is a link on SO about this: What is better: Static variable V.S. Asp.NET Application Session?
There are several thing we need to address here.
First of all, I think there are more code involved than the class you provided. I think you need to add that in order for us to give you an accurate answer.
However, from what I can see from the class you have provided, there is one thing in particular that you have done and that is the static
keyword.
The static
keyword on a class and/or a property means that there is only one instance in the entire application domain. This means that all requests to you website will share the values of your vars
class as there is only one instance.
I suggest you to follow some ASP.NET tutorials and videos, to gather some basic understanding in ASP.NET. Get started here, they have excellent material: http://www.asp.net/get-started
Read more on the static keyword: http://msdn.microsoft.com/en-us/library/98f28cdx(v=VS.100).aspx
精彩评论