2011-01-22 5 views
0

QueryString을 가져 와서 클라이언트에 파일을 스트리밍하는 ASP.Net 웹 페이지를 작성했습니다. 파일은 SQL Server 데이터베이스에 저장됩니다. 개발 과정에서 웹 사이트를 로컬로 실행할 때 모든 것이 잘 작동합니다. 서버에서 프로덕션 환경으로 실행하면 Firefox가 아닌 Chrome을 통해 파일을 가져올 수 있습니다. 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 

내 헤더

은 다음과 같습니다 : 여기

내 코드 내가 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

콘텐츠 처리를위한 코드가 깨졌습니다. (파일 이름이 공백을 포함하는 경우) 또는 이스케이프 (ISO-8859-1이 아닌 경우) –

+0

값을 따옴표로 묶으십시오. 헤더 검사에서도 따옴표로 묶여 있음을 나타내기도합니다. 아마도 당신이 말하는 것을 놓친 것 같습니다. – cjbarth

답변

0

을 (파이어 폭스 LiveHTTP 헤더는 마음에 온다), 및 Content-Length로 이상한 일이 일어나고 있는지 확인하기 (여러 번 설정)

+0

필자는 Fiddler2를 사용하여 모양이 틀렸고 머리글에 아무런 문제가 없음을 발견했습니다. 그러나 IIS가 gzip으로 응답하고 내 콘텐츠가 gzip으로되어 있지 않은 것으로 나타났습니다. 내 코드를 수정하여 콘텐츠를 gzip으로 만들었습니다. 이제 Firefox와 Chrome 모두 파일을 다운로드하고 있습니다. 그러나 진행률을 백분율로보고하지 않고 다운로드 한 바이트 만보고합니다. 또한 Fiddler2는 명시된 Content-Length가 실제 Content-Length보다 작은 Content-Length 불일치를보고합니다. – cjbarth

관련 문제