0

我编写了一个 ASP.Net 网页,它将获取一个QueryString文件并将其流式传输到客户端。该文件存储在 SQL Server 数据库中。当我在开发过程中在本地运行网站时,一切都很好。当我从服务器在生产中运行它时,我可以通过 Firefox 获取文件,但不能通过 Chrome 获取。在 Chrome 中我得到Error 100 (net::ERR_CONNECTION_CLOSED): Unknown error.

请参阅其他一些提到这可能与 相关的帖子Content-Length,但是,我不明白为什么这会在开发而不是生产中起作用。出于这个原因,我认为这里一定有其他事情发生。

感谢您的任何建议/提示。

这是我的代码:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim Data_ID As String = Request.QueryString("Data_ID")

    Using dt As New Enterprise_Error_Log.Field_FileDataTable
        Using ta As New Field_FileTableAdapter
            ta.Fill(dt, Data_ID)

            If dt.Rows.Count > 0 Then
                Dim myRow As Enterprise_Error_Log.Field_FileRow = dt.Rows(0)
                Dim myFileName As String = myRow("Field_File_Name")
                'Dim myFileData() As Byte = myRow("Field_File")
                Dim myFileLength As String = myRow("Field_File_Length")

                Response.BufferOutput = False
                Response.AddHeader("Content-Disposition", "inline;filename=""" & myFileName & """")
                Response.AddHeader("Content-Length", myFileLength)

                StreamFile(Data_ID)

                Response.Close()

            End If

        End Using
    End Using

End Sub

Private Sub StreamFile(ByVal Data_ID As String)
    Dim bolGotContentType As Boolean = False

    Using conn = New SqlConnection(Enterprise_Error_LogConnectionString.ConnectionString)
        Using cmd = conn.CreateCommand()
            conn.Open()
            cmd.CommandText = "SELECT Field_File FROM Ext_Error_Log WHERE (Data_ID = @Data_ID)"
            cmd.Parameters.AddWithValue("@Data_ID", Data_ID)

            Using reader = cmd.ExecuteReader(Data.CommandBehavior.SequentialAccess)
                While reader.Read()
                    Dim buffer As Byte() = New Byte(8040) {}
                    ' Read chunks of 1KB
                    Dim bytesRead As Long = 0
                    Dim dataIndex As Long = 0
                    Do
                        'read next chunk
                        bytesRead = reader.GetBytes(0, dataIndex, buffer, 0, buffer.Length)
                        If bytesRead > 0 Then
                            'advance index
                            dataIndex += bytesRead

                            'if this is the first chunk, get the mime type from it.
                            If Not bolGotContentType Then
                                Response.ContentType = "application/octet-stream" 'getMimeFromFile(buffer)
                                bolGotContentType = True
                            End If

                            Response.BinaryWrite(buffer)
                            Response.Flush()
                        End If
                    Loop Until bytesRead = 0

                End While

            End Using
        End Using
    End Using


End Sub

我的标题如下:

Cache-Control: private
Date: Mon, 24 Jan 2011 20:37:33 GMT

Content-Length: 3153269
Content-Type: application/octet-stream

Content-Disposition: attachment;filename="C:\Users\CBARTH\AppData\Local\Temp\tmp4BC8.mdmp.gz";size=3153169
Server: Microsoft-IIS/6.0
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET

Content-Encoding: gzip
4

1 回答 1

0

我建议检查 HTTP 跟踪工具中的实际响应(想到 Firefox LiveHTTP 标头),并检查 Content-Length 是否发生了奇怪的事情(设置多次?)

于 2011-01-22T10:02:37.513 回答