views:

273

answers:

3

In ASP.NET there is the Application_EndRequest event in global.asax. In classic ASP however there is no such equivalent event in global.asa

Is there any other built in way of handling the end request event, or any way of somehow hooking into IIS to accomplish the same thing?

Thanks

+4  A: 

We use a particularly twisted technique to execute code after the request has completed. Consider the following snippet:

Class EndRequestHandler
    Sub Class_Terminate()
        '' Handler code goes here
    End Sub
End Class

Set EndRequestHandlerInstance = New EndRequestHandler

When the request ends, ASP unloads all of the global variables, including EndRequestHandlerInstance, which calls it's Class_Terminate method. If you place this into an include file that's used by every page on the site, it should serve as your global end request handler.

Jason Musgrove
The only scenario where this technique may be useful is where you want to introduce "End Request" processing into an existing set of ASP pages that currrently share in ASP include. This code could be placed in the include. Personally I'd be uncomfortable doing much in a Class_Terminate that is running during script teardown.
AnthonyWJones
Why would you be uncomfortable? This method sounds ideal otherwise.
tgmdbm
+1  A: 

On IIS6 and older (or in an IIS7 classic pipeline application pool) you would really need to the help of an ISAPI filter to achieve the same sort of thing as a global End Request opertaion.

In IIS7 integrated pipeline you could use .NET End Request code even if the page executed is a classic ASP.

AnthonyWJones
A: 

Not being nosy but what is it that you are trying to do? There might be different solutions for what you want (such as rendering out debug goodies at the footer of each page) or no solutions at all (such as my wish that I could get the contents of the Response buffer and mess with it before farming it out to the wire)

Pete Duncanson
I'm trying to fix a memory leak.There's a circular reference which needs cleaning up before the objects involved will terminate. Also, the end request event is a nice place to put other such clean up code.
tgmdbm