Creating session variables in GLOBAL.ASA ???

R

RooLoo

Hey all

In my GLOBAL.ASA file I'm trying to create a session variable for reference
in the various webpages of my site....

Sub Session_OnStart
Session("LoggedOn")="Y"
End Sub

When referring to Session("LoggedOn") on my various ASP pages, it is coming
up as "".

I'm obviously misunderstanding how this works... Can anyone point me the
right direction?

Eventually I'll need to access a database and I'm assuming that if I need to
connect to that database, that I'll need to create the connection in the
Session_OnStart event and destroy the connection in the Session_OnEnd event
of the GLOBAL.ASA file.

Any help is appreciated!
 
A

Aaron Bertrand - MVP

Are you sure this global.asa is in a folder marked as an application? If it
isn't, it will use global.asa from the default webroot or the parent
application.

Are you sure sessions are working?
http://www.aspfaq.com/2057
 
T

Tom B

I don't see why what you've written wouldn't work, however your database
paragraph is incorrect. You DON'T want to open a connection that way. You
may want to store the connection string in a Session variable, but you
should open and close database connections on the individual pages.

Is your global.asa file in the root of the web application?
 
M

Matt Smith

RooLoo said:
Hey all

In my GLOBAL.ASA file I'm trying to create a session variable for reference
in the various webpages of my site....

Sub Session_OnStart
Session("LoggedOn")="Y"
End Sub

When referring to Session("LoggedOn") on my various ASP pages, it is coming
up as "".

A few things to notice:

1st: DON'T MULTIPOST!!!!

2nd: I think "Session_OnStart" should be "Session_OnStart ()"

3rd: Check the location of global.asa. Must reside in the root of your
application.

4th: Make sure you can have a Global.asa file. If you're hosting on a free
provider like
brinkster.com you'll probably not be allowed to use custom global.asa files.

5th: You'd probably be better off referencing this as a boolean value. Even
though all values are stored as variants there are always type-casting
issues, also you'll probably find yourself making niggly little mistakes in
case-sensitivity if you store this in a string.
Eventually I'll need to access a database and I'm assuming that if I need to
connect to that database, that I'll need to create the connection in the
Session_OnStart event and destroy the connection in the Session_OnEnd event
of the GLOBAL.ASA file.

No you won't: http://www.aspfaq.com/2053

Regards

Matt
 
S

Some One

Thanks for the quick reply.

The application variables are updating. I've got a "user" application
variable that updates fine in the same global.asa file.

In the GLOBAL.ASA file...
Sub Session_OnStart
Session("LoggedOn")="Y"
End Sub

In my ASP file...
<% response.write("LoggedOn = " & Session("LoggedOn") ) %>

....and it never displays anything except "LoggedOn="

P.s. Replying from home... That's why the different posting name.
 
A

Aaron Bertrand - MVP

The application variables are updating. I've got a "user" application
variable that updates fine in the same global.asa file.

In the GLOBAL.ASA file...
Sub Session_OnStart
Session("LoggedOn")="Y"
End Sub

Then the individual users are not accepting sessions. Did you look at
http://www.aspfaq.com/2057 ?
 
A

Aaron Bertrand - MVP

First, I DIDN'T! I CROSSPOSTED! I *DO* WATCH ALL OF THE GROUPS I
POSTED TO AND THEY ARE ALL RELATED.

Quit yelling. Two of the three groups you posted to do not exist on
msnews.microsoft.com, where most people get this feed from. If you use
msnews.microsoft.com as your news server, you'll get the same error that
everyone else gets every time they try to reply to your post.
Actually, it is... I didn't include the brackets in my news posting.

Always copy the exact code you're using, rather than transcribing (which can
lead to errors and miscommunications, like this one). Would you bring your
friend's car into the mechanic when yours won't start? They're both Civics,
right?
 
A

Aaron Bertrand - MVP

As for the groups not existing.. I have used the msnews server and
find that it isn't as reliable as my own server. Very often the msnews
server will just sputter out and die and no posts appear for days.

You should still check that the groups you see and post only to those you
know others will see. Of course, you might not have known that, but please
keep that in mind in the future.

Also, it is very rare you need to cross-post, pick a group... if it's the
wrong one, people will direct you elsewhere.
I do appreciate the help.... Thanks!

Once again, did you even *LOOK* at http://www.aspfaq.com/2057
 
S

Some One

Evertjan. said:
Some One wrote on 17 jul 2003 in microsoft.public.inetserver.asp.general:

What is the sense of setting this in Global.asa ??

Wouldn't testing on the existence of a session ID give the same results as
testing on your Session("LoggedOn") ?

Session("LoggedOn")="Y" being ste AFTER testing for it is usefull as it can
trigger special code in the first page of a session, or preventing someone
to start browsing anywhere else but on the homepage. This last method
should not be applied without a robots.txt file to keep googling
healthy.

Yes.. by itself this is silly, but I'm trying to figure out why it
doesn't work.

My intention is to create a session variable with a access level value
that will hide certain features, depending on it's value. This won't
work if all I ever get is "0".
 
S

Some One

Aaron Bertrand - MVP said:
You should still check that the groups you see and post only to those you
know others will see. Of course, you might not have known that, but please
keep that in mind in the future.

Actually, I did notice that they didn't exist on the MS server when I
arrived home and went looking for the groups, but there were postings
in at least one of the other groups, so I know others are using it.
Also, it is very rare you need to cross-post, pick a group... if it's the
wrong one, people will direct you elsewhere.

Once again, did you even *LOOK* at http://www.aspfaq.com/2057

Yup... "How can I tell which version of MDAC I'm running?" Doesn't
seem really relevant to me.

I think you meant http://www.aspfaq.com/show.asp?id=2157 ... but none
of the comments on that page have helped with this issue.

I'm pretty sure it's just me doing something stupid, but I don't see
it.
 
E

Evertjan.

Some One wrote on 17 jul 2003 in microsoft.public.inetserver.asp.general:
Yes.. by itself this is silly, but I'm trying to figure out why it
doesn't work.

It could be, that the session is not yet ready for its variables at that
time ?
My intention is to create a session variable with a access level value
that will hide certain features, depending on it's value. This won't
work if all I ever get is "0".

If you define the nonexistence [= zero string] of the sessionvariable as
maximum hide, same as level 17, it is possible.

In your protected pages:

<%
if session("accesslevel")="" then session("accesslevel")=17

if session("accesslevel")<8 then then response.redirect "noadmittance.asp"
%>

Global.asa problem solved ?
 
T

Tom B

Evertjan had a thought. Why not (as a test) set up a page and set your
session variable there, to see if it's working. Then you'll know that it's
for sure global.asa
 
S

Some One

That helped a lot...

Not sure what I was doing wrong, but I moved my files to a new folder
and re-setup the webpage in IIS and it's working fine now.

I don't see any difference in the settings, but I'm not complaining.

Thanks guys!!!
 
J

Julia Mark

Can anyone help me how to make keyevents for richtextbox in javascript or
WYSIWYG editor

all i am working on a textarea where X number of char reaches in a line then
the function to move the next line with inserting break.


Julia Mark
 
J

Julia Mark

Can anyone help me how to make keyevents for richtextbox in javascript or
WYSIWYG editor

all i am working on a textarea where X number of char reaches in a line then
the function to move the next line with inserting break.


Julia Mark
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top