This is a very trivial example of using the Response.IsClientConnected property. Basically, you have a file where you are doing a lot of processing, and you only want to continue if the user is still connected to the ASP page. You can test this while the page is still executing; in the following example, we have one big loop, followed by another. Before entering the second loop, we test if the client is still connected, and then again after the second loop. This is just to populate the text file, to demonstrate how this works. Load this page once, and let it finish. Then, hit Ctrl+Refresh and close the browser (or hit Stop) before the page finishes executing, and examine the different lines in your log file.
<% set fso = CreateObject("Scripting.FileSystemObject") set fs = fso.OpenTextFile(Server.MapPath("/log.txt"),8,true) fsStuff = now & " - gone during first loop" for i = 1 to 1000000 boo = "" next if response.isClientConnected then fsStuff = now & " - gone during second loop" for j = 1 to 1000000 hoo = "" next if response.isClientConnected then fsStuff = now & " - " & i+j end if end if fs.writeline fsStuff response.write fsStuff fs.close: set fs = nothing set fso = nothing %> |
It should be relatively easy to port this logic to your own code.
You might get this error:
Microsoft VBScript runtime error '800a01b6' Object doesn't support this property or method: 'Response.IsClientConnected' |
If so, you need to be using a
newer version of IIS.