session variables and global.aspx.cs - where do i put them?

  • Thread starter Thread starter tony collier
  • Start date Start date
T

tony collier

if i put an array in

public class Global : System.Web.HttpApplication
{

//e.g.

public static int [] count=new int[5]

}

and then refer to it in my page .cs files as Global.count[0].... [4] will
every session in my application be accessing the same count array or will
they each have their own?

I guess i am really saying is, is there a difference between the above and
:

protected void Session_Start(Object sender, EventArgs e)
{

Sesson["count"]=new int[5]

}


It strikes me that if they are the same then the first option is better
because i don't have to keep casting from object to int everytime i access
the array in web pages.
 
Hi Tony,

You should think of the Application scope the same way you would think of Environment variables.
They are not only global, but they are also readable and writable to all users of the system at the same
time.

Session is better to use if the values are not final or need to be changed per user.
A session is created for each user making a request.

____________________________________
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Business | Personal
 
Back
Top