PDA

Click to See Complete Forum and Search --> : global variables


DrewDog_21
Mar 30th, 2001, 01:48 PM
How should I go about declaring global variables for my ASP pages? I want to have some variables that will be constant throughout the pages. Is there some way that I can store all of them in the same page and then include them with the other pages, like a VB module?

compuGEEK
Mar 30th, 2001, 01:59 PM
You should be able to use the global.asa file. :D

Wait, let me clarify that a bit:
You can create a session variable in the global.asa file so that every asp page will have access to it.

JoshT
Mar 30th, 2001, 02:28 PM
You could store them all in a file and use Server-Side Includes on each page to get it.

DrewDog_21
Mar 30th, 2001, 02:32 PM
Thanks guys for the suggestions

compuGeek - how do I go about creating a session variable? I am new to ASP. I put

<!-- include file "global.asa" -->

in all of the files, and that seems to work, albeit a bit inefficiently.

harsoni
Mar 30th, 2001, 02:46 PM
My suggestion is try to avoid session variables, it is has lots of disadvantages, for more info check msdn.microsoft.com..

Sonia

Mar 30th, 2001, 03:37 PM
You create a session variable like this:

Session("strUserName") = "bubba"

You can change the value of a session variable at anytime.

Some (potential) problems with session variables are;

They are stored in memory, so if you have a lot of users connected at once and your session variables contain a lot of data, there could be performance issues;

If the user disables cookies on their browser, session variables don't work;

If you are using a web farm, and your re-directs contain the complete url (response.redirect "http://newasp.asp") rather than the logical path (response.redirect "../newdir/newpage.asp ") the session variables could be lost.

Of course, these problems do not always occur, and there are other potential problems (which I'm sure somebody will point out) that may present themselves.