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    
End Sub

Sub Session_OnEnd
End Sub

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

    response.write("Session Counter Equals:  ")

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:

    <asp runOnEndAnonymously="false" />


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

No Comments