How can I make a static (or "global") variable in classic ASP?

I want to make my static or "global" variable the same as static in .NET; every session that accesses it gets the same result, and if one session changes it, it affects everyone else.

How can I achieve this in classic ASP?

+4
source share
2 answers

If you want to have a variable that is publicly available, you can use the application object. Be sure to use Application.Lock / Unlock to prevent any problems.

Application.Lock Application("MyVariable") = "SomeValue" Application.Unlock 
+6
source

using session variable

 Session("myVariableName") = "my new value" 

the area will be the user ...

if you want to expand the scope for ALL users who are on the website, then you use the Application variable

 Application("myVariableName") = "my new value" 

you can reset or handle this in global.asa file as well

This is a common thing:

global.asa file :

 <script language="vbscript" runat="server"> Sub Application_OnStart Application("visitors") = 0 End Sub Sub Session_OnStart Application.Lock Application("visitors") = Application("visitors") + 1 Application.UnLock End Sub Sub Session_OnEnd Application.Lock Application("visitors") = Application("visitors") - 1 Application.UnLock End Sub </script> 

default.asp :

 <html> <head> </head> <body> <p>There are <%response.write(Application("visitors"))%> online now!</p> </body> </html> 
+4
source

All Articles