我写了一个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
答案 0 :(得分:0)
我建议在HTTP跟踪工具中检查实际响应(想到Firefox LiveHTTP标题),并检查Content-Length是否有异常(多次设置?)