User cancels file download and aspnet_wp.exe recycles

Fade

Newcomer
Joined
May 30, 2003
Messages
9
Location
Australia
Hi all,

I have an ASP.net website that uses an aspx page locate and stream a file to an authenticated user and I'm getting the error:
Aspnet_wp.exe (PID:XXXX) stopped unexpectedly.

which the user sees as the Server Unavailable page.

I am aware of problems using Response.BinaryWrite or Response.WriteFile to download large files and so opted for the chunked method described in the microsoft KB article 812406.

The problem is that when a user cancels the download, the website stops responding. If the user then attempts to start a new download, either nothing happens or they get a Server Unavailable and my aspnet_wp.exe gets recycled.

If I step though the code and watch the file streaming out, then cancel the download before it completes, the loop continues for a while then stops. Hitting break and trying to check the values of the context, request or response objects gives me "error: cannot obtain value".

My attempts at using BinaryWrite and WriteFile met with similar problems. I have seen reference to a hotfix that adds a Response.TransferFile method but I'm not sure if this is caused by the same problem (aspnet running out of memory space), even though the symptoms are the same (recycled aspnet_wp.exe)

Has anyone had similar problems? if so, will the hotfix correct it?

I have found a few other posts on this problem around the net (mostly dated 1-2 years ago) but not a single response!

please help!
 
Here's the download code before anyone asks! :)

Code:
     Dim iStream As System.IO.Stream

      ' Buffer to read 10K bytes in chunk:
      Dim buffer(10000) As Byte

      ' Length of the file:
      Dim length As Integer

      ' Total bytes to read:
      Dim dataToRead As Long

      ' Identify the file to download including its path.
      Dim filepath As String = "DownloadFileName"

      ' Identify the file name.
      Dim filename As String = System.IO.Path.GetFileName(filepath)

      Try
         ' Open the file.
         iStream = New System.IO.FileStream(filepath, System.IO.FileMode.Open, _
                                                IO.FileAccess.Read, IO.FileShare.Read)

         ' Total bytes to read:
         dataToRead = iStream.Length
         
         Response.ContentType = "application/octet-stream"
         Response.AddHeader("Content-Disposition", "attachment; filename=" & filename)

         ' Read the bytes.
            While dataToRead > 0
                ' Verify that the client is connected.
                If Response.IsClientConnected Then
                    ' Read the data in buffer
                    length = iStream.Read(buffer, 0, 10000)

                    ' Write the data to the current output stream.
                    Response.OutputStream.Write(buffer, 0, length)

                    ' Flush the data to the HTML output.
                    Response.Flush()

                    ReDim buffer(10000) ' Clear the buffer
                    dataToRead = dataToRead - length
                Else
                    'prevent infinite loop if user disconnects
                    dataToRead = -1
                End If
            End While

      Catch ex As Exception
         ' Trap the error, if any.
         Response.Write("Error : " & ex.Message)
      Finally
         If IsNothing(iStream) = False Then
            ' Close the file.
            iStream.Close()
         End If
      End Try
 
The entire event viewer error message - so no, not all that helpful unfortunately..

Event Type: Error
Event Source: ASP.NET 1.1.4322.0
Event Category: None
Event ID: 1000
Date: 30/04/2004
Time: 3:24:44 PM
User: N/A
Computer: SERVER01
Description:
aspnet_wp.exe (PID: 4508) stopped unexpectedly.


and yes, that is the hotfix I've read about. I may have to just call microsoft and explain this problem to them. I expect they'll just tell me to apply the hotfix.
 
Back
Top