문제

나는 Chrome 에서이 이상한 행동으로 벽에 머리를 두드리고 있습니다.

명명되지 않은 상태로 디스크에 암호화 된 파일이 저장되어 있습니다. 사용자가 파일을 다운로드하면 클라이언트가 다운로드 핸들러 (.ASHX)로 리디렉션됩니다. 데이터는 스트림에로드되어 해독되어 클라이언트로 전송됩니다. 이제 이것은 최근까지 잘 작동했습니다.

파일을 .gz 파일로 다운로드하고 읽을 수없는 Chrome을 제외한 모든 브라우저에서 잘 작동합니까?

나는 간결함을 위해 스트림 페치 및 암호화 부분을 제거했습니다 (IE, Firefox 등에 완벽하게 작동합니다).

    Private Function StreamFile(ByVal context As System.Web.HttpContext) As Boolean

    context.Response.Clear()
    context.Response.ClearHeaders()
    context.Response.BufferOutput = False
    context.Response.ContentType = "application/octet-stream"
    context.Response.AddHeader("content-disposition", "attachment;filename=""" & _sFileName & """")
    context.Response.AddHeader("content-length", _iSize)
    context.Response.Cache.SetNoServerCaching()
    context.Response.Cache.SetMaxAge(System.TimeSpan.Zero)

    Dim oInputStream As System.IO.Stream = GetStream()
    Dim oBufferedStream As New BufferedStream(oFileStream, context.Response.OutputStream)
    oBufferedStream.ProcessStreams(True)

    context.ApplicationInstance.CompleteRequest()

    Return True

End Function

Public Class BufferedStream
    Private _oInputStream As Stream
    Private _oOutputStream As Stream
    Private _bBuffer() As Byte
    Public Const DEFAULT_BUFFER_SIZE As Integer = 8192

    Public Sub New(ByRef oInputStream As Stream, ByRef oOutputStream As Stream)
        _oInputStream = oInputStream
        _oOutputStream = oOutputStream
        _bBuffer = GetStreamBuffer(ToInteger(_oInputStream.Length))
    End Sub

    Public Function ProcessStreams(ByVal bCloseStreams As Boolean) As Boolean

        Dim iRead As Integer = 0
        Dim iStreamLength As Integer = ToInteger(_oInputStream.Length)

        Try
            iRead = _oInputStream.Read(_bBuffer, 0, _bBuffer.Length)
            While iRead > 0
                _oOutputStream.Write(_bBuffer, 0, _bBuffer.Length)
                iRead = _oInputStream.Read(_bBuffer, 0, _bBuffer.Length)
                If iRead < _bBuffer.Length Then System.Array.Resize(_bBuffer, iRead)
            End While

            If bCloseStreams Then
                Close()
            End If
            Return True

        Catch
            Return False
        End Try
    End Function

    Public Shared Function GetStreamBuffer(ByVal iStreamSize As Integer) As Byte()
        Dim iBufferSize As Integer = iStreamSize - 1
        If iBufferSize > DEFAULT_BUFFER_SIZE Then iBufferSize = DEFAULT_BUFFER_SIZE
        Dim bBuffer As Byte() = New Byte(iBufferSize) {}
        Return bBuffer
    End Function

End Class

모든 도움은 대단히 감사하겠습니다.

파일이 Chrome에서 다운로드 될 때 Fiddler의 HTTP 헤더는 다음과 같습니다.

HTTP/1.1 200 OK
Date: Fri, 30 Oct 2009 00:01:45 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
content-disposition: attachment;filename="codeKiwi.txt"
Content-Length: 349
Cache-Control: private, max-age=0
Content-Type: application/octet-stream

파일 이름은 codekiwi.txt이고 내용은 간단한 일반 텍스트이며 파일은 codekiwi.txt.gz로 저장되고 gribberish를 포함합니다.

도움이 되었습니까?

해결책

좋아, 직접 해결했다. Chrome (및 Firefox)은 실제로 응답을 좋아하지 않는다는 것이 밝혀졌습니다. Clearheaders Call, 어떤 이유로 든 IE는 괜찮 았습니다. 일단 제거하면 다운로드가 다시 예상대로 작동했습니다 ...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top