首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > ASP >

asp中IsClientConnect的用法疑惑解决思路

2012-03-09 
asp中IsClientConnect的用法疑惑书上说:IsClientConnected 属性指示出客户机是否已与服务器断开连接。给出

asp中IsClientConnect的用法疑惑
书上说:IsClientConnected 属性指示出客户机是否已与服务器断开连接。

给出的例子是:
<%
If response.IsClientConnected=true then
  response.write("The user is still connected!")
else
  response.write("The user is not connected!")
end if
%>
我想知道如何操作能让这个程序输出The user is not connected!
有没有更好的例子能说明一下response.IsClientConnected的用法(特别是怎样操作是它为false)

[解决办法]
断开连接就不往客户端发送内容了。你看不到等于false的情况。

这种判断适用于运行时间比较长的代码,浏览器突然点击了 停止 就会导致IsClientConnected=false

[解决办法]
比如传递大文件的时候, 客户端断了就不要传了

VBScript code
Function TransferFile(ByRef oStream, sMimeType, sFilename)    Dim iChar, iSent, iSize    Dim c    Const FILE_TRANSFER_SIZE    = 32768 '32k    iSent            = 0    TransferFile    = True    iSize            = oStream.Size    With Response         .Charset    = "GB2312"        .ContentType= sMimeType        .AddHeader "Accept-Ranges", "bytes"        .AddHeader "Content-Length", iSize        .AddHeader "Content-Type", sMimeType        .AddHeader "DownloadOptions", "noopen"        .AddHeader "Content-Disposition","attachment; filename=" & sFilename    End With    c    = 0    Do While c <= iSize        iChar = oStream.ReadBin(FILE_TRANSFER_SIZE)        c    = c + FILE_TRANSFER_SIZE        With Response            .BinaryWrite(iChar)            iSent = iSent + FILE_TRANSFER_SIZE            If (iSent MOD FILE_TRANSFER_SIZE) = 0 Then                .Flush                If Not .IsClientConnected Then                    TransferFile = False                    Exit Do                End If            End If        End With    Loop    Response.Flush    If Not Response.IsClientConnected Then TransferFile = False    Set oStream = NothingEnd Function 

热点排行