globalization

D

Daves

still trying to set variables for use in all sub-pages...

thought I'd found the solution with global.ascx:
Application("connstring") = "...";
Session("UserID") = 0;

well it turns out the application and session objects are not pure system
int/string type of objects so that each time I access them I have to use a
cast eg
if ((int) Session("UserID") >0) ...

I think this is not a good way so how oh how can I just add constants to the
global class and then
if (global.UserID >0) ...

???
 
D

Daves

hmm sorry I've learned that "globalization" refers to something else than
using variables set "globally" in global.ascx

still... please can someone help me on this so easy thing: to set a static
variable in global.ascx to use in all sub-pages?!
 
R

recoil

Variables/Classes are stored as "Objects" in your Session.
so you should do something like this
if (Session("UserID") is null) then
Session("UserID") = 100
Else
' session is already set to use it you have to cast it to an int
dim p as int = (Int) Session("UserID")
End if
I "think" this code will work. Basically you need to check to see if
the object exists. If it does not exist you need to initialize it to a
value.


If this does not solve your problem then try to rephrase your question
and provide more details.
Remember that Sesion Variables are specific to a user's web session
where as application are specific to the whole website.
Information about a user would be stored in a session. rmembering that
when the user is idle for more hten 20 minutes this information is
lost.
Information about the whole site woudl be stored in your Application.
This information is lost if the application is restarted for any reason
or the web server is restarted.
 
D

Daves

thx, this is true - it works by casting and I do watch out not having them
set as null.
But I still want to access the variables just as simple class (static)
properties; they are easier to access (global.UserId rather than (int)
Session("UserID")) and as I understand the case they are easier load on the
server
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top