Partager via


Session_OnEnd, Classic ASP and IIS 7.0

I have found that a classic ASP application that worked just fine on IIS 5.0 and IIS 6.0 may have some problems in IIS 7.0 if it is making use of the Session_OnEnd function in Global.asa.

Here is the set up, I have a very simple global.asa file which increments SessionCount in Session_OnStart and decrements SessionCount in Session_OnEnd:

 

Sub Session_OnStart Application("SessionCount")=Application("SessionCount")+1 End Sub

Sub Session_OnEnd Application("SessionCount")=Application("SessionCount")-1 End Sub

and a very simple asp page which reports the value of SessionCount.

<% response.write("Session Counter Equals: ") response.write(Application("SessionCount")) %>

Seems simple enough right?

Well it is, and on IIS 5.0 and IIS 6.0 this simple set up works just as expected.  However, on IIS 7.0 the session count never decrements.

To allow Session_OnEnd to execute correctly we need to set RunOnEndAnonymously=False.  To set this value we just need to run this command:

appcmd set config /section:system.webServer/asp /runOnEndAnonymously:false

Once this change is made the applicationhost.config should have the following entry:

<system.webServer> <asp runOnEndAnonymously="false" /> </asp> </system.webServer>

After this the Session_OnEnd event should fire and run successfully. 

NOTE: We could also use adsutil.vbs to make the needed change. IIS 6.0 Management Compatibility Role Service will need to be installed.  Once it is installed we need to run this command to make the needed change:

cscript.exe c:\inetpub\adminscripts\adsutil.vbs set w3svc/AspRunOnEndAnonymously false

Comments