0

I'm trying to just output the global.asa Application("SiteURL"), but I get nothing showing for SiteURL. I have it defined in the global.asa as

    <!--METADATA TYPE="TypeLib" FILE="c:\Program Files\Common Files\System\ado\msado15.dll" -->

    <SCRIPT LANGUAGE="VBScript"  RUNAT="Server">
       Sub Application_OnStart
          Application("SiteURL") = "http://[localhost]/asp3test/" 
          Application("myAppVariable") = "Apple" 
          Application("CurrentDateTime") = ""  
       End Sub
   </SCRIPT>

This is my test.asp file:

 <BODY>
 Let's retrieve the values of the Application Variables:<P>
 myAppVariable = <%= Application("myAppVariable")%><BR>
 SiteURL = <%= Application("SiteURL")%> <br />
 CurrentDateTime = <%= Application("CurrentDateTime")%><br />

 Now, let's set the variables:<HR>
 <%
 Application.Lock
 Application("CurrentDateTime") = Now
 Application.UnLock
 %>
 Variables set - <A HREF="test.asp">click here</A> to reload the page to view
 </BODY>

Result:

Let's retrieve the values of the Application Variables:

myAppVariable =
SiteURL =
CurrentDateTime = 12/22/2013 1:47:42 PM
Now, let's set the variables:

The values that are set in the Global.asa file do not seem to be grabbed, like it is not being read (processed), but when I manually set the values to a Application(variable), it seems to hold it. So something missing with with Global.asa is not being read. I am on IIS 7.5.76 and Win7(64bit), not sure if that helps.

user1929393
  • 4,089
  • 7
  • 30
  • 48
  • 1
    I've removed the ASP.NET tag. ASP.NET and Classic ASP are **not** the same thing. – Tim Dec 22 '13 at 08:51

2 Answers2

3

Have you got it inside the correct Sub within your global.asa? i.e.

Sub Application_OnStart
    Application("SiteURL") = "http://[localhost]/asp3test/"
End Sub
Polynomial
  • 3,656
  • 23
  • 36
  • I added some additional info. But yes, they are in the global.asa – user1929393 Dec 22 '13 at 18:52
  • And `test.asp` is in the root of the virtual server? – Polynomial Dec 22 '13 at 23:14
  • I read somewhere that I need to change the name of the Application Directory on IIS? http://stackoverflow.com/questions/1427779/classic-asp-asp-net-website-global-asa-not-working – user1929393 Dec 22 '13 at 23:23
  • If `test.asp` is in a directory with its own application then it cannot access the variables of the root application. – Polynomial Dec 22 '13 at 23:31
  • There is no folder. All files are on the same root for this website. I wonder if I have configured it correctly? – user1929393 Dec 23 '13 at 01:19
  • @user1929393 try causing error in `global.asa` on purpose e.g. remove `End Sub` line. If you don't get any error when viewing the .asp page it means the `global.asa` file is not being called, better ask new question in that case. If you do get error it means problem with the code itself and we'll debug it further. – Shadow The GPT Wizard Dec 23 '13 at 08:55
0

My website was not setup correctly... I had to add application to the default website for it to work. The reason it did not work before is because I created just a website separate from the default website, and did not ADD Application to that website. However, I was getting an error trying to create add application in IIS. I heard somewhere this is a bug. That tripped me up.

user1929393
  • 4,089
  • 7
  • 30
  • 48