J'ai écrit une page Web ASP.Net qui prendra un QueryString
et diffusera un fichier au client. Le fichier est stocké dans une base de données SQL Server. Tout fonctionne très bien lorsque je cours le site Web localement pendant le développement. Quand je l'exécute en production à partir du serveur, je peux obtenir un fichier via Firefox, mais pas Chrome. Dans Chrome, je reçois Error 100 (net::ERR_CONNECTION_CLOSED): Unknown error.
Stream File à Chome cassé, Firefox de travail
Voir d'autres messages qui mentionnent cela pourrait être lié à Content-Length
, cependant, je ne comprends pas pourquoi cela fonctionnerait en développement et non en production. Pour cette raison, je pense qu'il doit y avoir quelque chose d'autre ici.
Merci pour vos suggestions/conseils.
Voici mon code:
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
Mes têtes sont les suivantes:
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
votre code pour le remplissage Content-Disposition est cassé; vous devrez peut-être citer la valeur (par exemple, lorsque le nom de fichier contient des espaces) ou même l'échappement (pour non-ISO-8859-1) –
La valeur est citée, même l'inspection d'en-tête montre qu'elle est citée. Peut-être que je ne comprends pas de quoi vous parlez. – cjbarth