2011-01-22 17 views
0

私はQueryStringをとり、ファイルをクライアントにストリームするASP.Net Webページを作成しました。ファイルはSQL Serverデータベースに格納されます。開発中にウェブサイトをローカルで実行しているときは、すべてがうまく動作します。私はサーバーからプロダクションでそれを実行すると、FirefoxではなくChromeでファイルを取得できます。クロムで私は得るError 100 (net::ERR_CONNECTION_CLOSED): Unknown error.壊れたストリームファイル、Firefox動作

これは、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 

私のヘッダーは次のとおりであります(FirefoxのLiveHTTPヘッダーが頭に浮かぶ)私は、HTTPのトレースツールで実際の応答を検査をお勧めします

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

Content-Dispositionのコードが壊れています。 (ファイル名に空白が含まれる場合など)、エスケープ(ISO-8859-1以外の場合)の場合は、値を引用符で囲む必要があります。 –

+0

ヘッダー検査でも値が引用されている場合でも値は引用符で囲まれます。おそらく私はあなたが何を指しているのか分からない。 – cjbarth

答えて

0

、およびContent-Lengthで奇妙なことが起こっているかどうかを確認します(複数回設定しますか?)

+0

私はFiddler2を使って見て、ヘッダーに間違いがないことを発見しました。しかし、IISがgzipで応答していて、コンテンツがgzipされていないことに気付きました。コンテンツをgzipするようにコードを修正しましたが、FirefoxとChromeの両方がファイルをダウンロードしています。しかし、いずれも進行状況をパーセンテージとして報告しておらず、ダウンロードされたバイトを報告しているだけです。さらに、Fiddler2は、記載されたContent-Lengthが実際のContent-Lengthよりも小さいContent-Lengthミスマッチを報告しています。 – cjbarth

関連する問題