Dmitrij Holkin
Dmitrij Holkin

Reputation: 2055

Asp3 define Global variable on sessionless

How can I define a variable that is accessible over several #include levels? E.g. I have some DIM declared in a VBScript and I want to access this by name inside an included VBScript so it is accessible for one user/one session which must be equal to session("UserID") if I have disabled sessions at all and also do not use cookies.

Upvotes: 1

Views: 146

Answers (4)

Yagami
Yagami

Reputation: 23

Sessions also use cookies to track visitor. But ASP-SessionID Cookie does not have an expire time so if you close your browser, your cookie with ASP-SessionID will delete and your session will be terminated. i think you try to build a load balance on an ASP site which is most complicated thing with session variables. You have to use something different to track visitors. Cookies are an option but you have to create your own session management and still have to use a cookie to remember it.

i found a new component to do this. it work like a charm for load balance and keep your own session management with multi accesible mechanism.

http://www.aspstate.com/Developer/Documentation/html/R_Project_Documentation.htm

Upvotes: 1

Frank
Frank

Reputation: 1056

Cookies, sessions (cookie-sessions), local storage values, are the most common types to track a visitor. Another unrealiable option is to store the values in a DB table and then use a mix of IP address and other browser sniffing variables to indicate a user (this is a bad idea).

Your best bet is to use standard cookies and keep ASP-SESSIONS off. Then you would have to build your own session management, which is usually done in a Database.

As for getting those session values into ASP and playing with them on the server side, you just do a request.cookies("session-coookie-name") and then look up the session in your DB. If you want this to go across all pages of your site put it in an include file and make sure that include file is included in all of your asp scripts.

When coding Classic asp, I usually start with a boiler plate which has a few includes (include-page-start.asp, include-head-asp, include-menu.asp, include-page-end.asp). Having an approach like this allows you to quickly add functionality without having to edit every page later. Remember includes can also include other includes :) (part of the reason asp classic both sucks and rocks!)

Upvotes: 1

Jonathan
Jonathan

Reputation: 1296

If you want to keep the variable state through multiple page requests and can't use cookies nor session state, an option i see is carrying it in the query string of each request url.

Or maybe you can also look at html5 local storage. Despite some people depreciating w3schools, i always find it a good starting point.

Upvotes: 3

Zohar Peled
Zohar Peled

Reputation: 82524

Well, it's been a very long time since I've last worked with ASP3 and VBScript, but if memory serves, the #Include directive is actually not a part of the ASP, it's an instruction to the IIS to add the file that is included into your ASP page.
Therefor any function or variable declared in an included file should be considered for all intents and purposes as if it was written directly into your ASP page.
As you should know, VBScript can't use a variable unless it's declared in a previous code row, therefor it's only a matter of where in your ASP page you are using the #Include directive.
This is why you should use the #Include directive as soon as possible in the ASP page that uses them.

Upvotes: 1

Related Questions