2

Forgive me if this is a dumb question, I'm new to ASP. I have a virtual Windows Server 2012 handling ASP pages, passing them to the host for testing purposes. There is a global.asa file which declares several Application-level variables, though it doesn't seem to be working. I'm not sure if I need to call the file or what, though I can't find any reference to calling it on the internet.

In global.asa:

<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Application_OnStart
    Application("someVar") = "testing..."
    'More vars...
End Sub
</SCRIPT>

In default.asp: (Or any other file for that matter)

Repsonse.Write(Application("someVar"))

Nothing will output.

However, if I specify a value immediately beforehand like so:

Application("someVar") = "testing..."
Repsonse.Write(Application("someVar"))

It will output "testing..." like it should.

After that, removing the Application("someVar") = "testing..." line will still output "testing...". So the variable is being retained, it just isn't being set initially by the global.asa file.

Is there something else I need to do to initialize them via the global.asa file? Is it a problem with my virtual server setup? I should probably mention that navigating to the global.asa file via the web browser gives me a 404 error. I'm not sure if the server is trying to hide it, but I am as certain as I can be that it is in the same directory as default.asp, the browser just refuses to verify this.

Kara
  • 6,115
  • 16
  • 50
  • 57
Doug
  • 387
  • 2
  • 10
  • 20
  • According to [w3schools](http://www.w3schools.com/asp/asp_globalasa.asp) (yes I know) you need to restart your server whenever you make changes to the Application_OnStart subroutine. – Lee Avital Jun 27 '13 at 16:52
  • That is something I overlooked, however restarting doesn't seem to help. It does clear the variables I manually set outside the global.asa file (which makes sense). But they are still not initialized as the global.asa would indicate. – Doug Jun 27 '13 at 17:15
  • The official docs are [here](http://msdn.microsoft.com/en-us/library/ms525316%28v=vs.90%29.aspx), and [this SO question](http://stackoverflow.com/questions/559076/global-asa-where-does-it-belong) might help. – Cheran Shunmugavel Jun 28 '13 at 06:34
  • One of those links makes reference to defining the application in IIS, something I don't believe I have done. Where would I go to add that in? All I can find is "Application Settings" which allows me to add a name-value pair, but I have no idea what it represents. I am using IIS 8. – Doug Jun 28 '13 at 15:17
  • @Lee wrong, editing that file is causing the application pool to be recycled no need to restart. – Shadow The GPT Wizard Jun 30 '13 at 11:39
  • As for the problem you face, sounds like the classic ASP code is not in its own standalone site. If not, add new site and put the code there. If it's already a site, try giving it its own application pool. – Shadow The GPT Wizard Jun 30 '13 at 12:10
  • You need to do an application lock and unlock between writing application variables in classic asp applications. – Frank Aug 31 '13 at 22:54

2 Answers2

0

Global iis defined application variables will not work if the site isn't set as a application.

You need to open IIS, and setup the website as new site.

open iis manager expand servername, expand 'Sites' Any sites you have will be listed.

to setup new site r-click on 'sites' and select 'Add Web Site' Give it a name, select its location by browsing, and if needed set the host header eg www.mytestdomain.co.uk

OR (this is often the cause in test setups)

If you have a default site setup and this application is a subfolder then you can set that subfolder as an application by simply right clicking on folder and choose 'Convert to application'. click ok on the popup to confirm.

RyGa
  • 13
  • 1
  • 4
0
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Application_OnStart
    Application("someVar") = "testing..."
    'More vars...
End Sub
</SCRIPT>

May be, you set the var someVar in Global.asa after the application is already running! And if so, Application_OnStart event is already executed!!!

Keith
  • 20,636
  • 11
  • 84
  • 125