Проблема решена.
Я изменил буфер с Object на Byte, и это сработало !!!
Старый код (часть обработчика):
context.Response.ContentType = "application/pdf"
Dim strm As Stream = ShowNewsImage(imgName)
If Not strm Is Nothing Then
Dim buffer As Byte() = New Byte(4095) {}
Dim byteSeq As Integer = strm.Read(buffer, 0, 4096)
Do While byteSeq > 0
context.Response.OutputStream.Write(buffer, 0, byteSeq)
byteSeq = strm.Read(buffer, 0, 4096)
Loop
context.Response.BinaryWrite(buffer)
context.Response.End()
End If
End Sub
Public Function ShowNewsImage(ByVal imgName As String) As Stream
Dim conn As String = ConfigurationManager.ConnectionStrings("Connection").ConnectionString
Dim connection As SqlConnection = New SqlConnection(conn)
Dim sql As String = "SELECT image FROM Table WHERE ID = @ID"
Dim cmd As SqlCommand = New SqlCommand(sql, connection)
cmd.CommandType = CommandType.Text
cmd.Parameters.AddWithValue("@ID", imgName)
connection.Open()
Dim img As <strong>Object </strong>= cmd.ExecuteScalar()
Try
Return New MemoryStream(CType(img, Byte()))
Catch
Return Nothing
Finally
connection.Close()
End Try
End Function
Как видите, ExecuteScalar () прикрепил вывод к объекту.Я изменил это на Байт:
context.Response.ContentType = "application/pdf"
Dim buffer As Byte() = New Byte(4095) {}
Dim byteSeq As Integer = 0
Dim conn As String = ConfigurationManager.ConnectionStrings("Connection").ConnectionString
Dim connection As SqlConnection = New SqlConnection(conn)
Dim sql As String = "SELECT image FROM Table WHERE ID = @ID"
Dim cmd As SqlCommand = New SqlCommand(sql, connection)
cmd.CommandType = CommandType.Text
cmd.Parameters.AddWithValue("@ID", imgName)
connection.Open()
buffer = cmd.ExecuteScalar()
context.Response.BinaryWrite(buffer)
context.Response.End()
Нет необходимости в context.Response.OutputStream.Write, он уже заблокирован в context.Response.BinaryWrite
У меня ушло два дня.