Pergunta

Eu tenho sido batendo minha cabeça contra a parede com este comportamento estranho no Chrome

Eu tenho arquivos armazenados criptografados no disco em um estado sem nome, não ordenada. quando os arquivos são baixados pelo usuário, o cliente é redirecionado para um manipuladores de download (.ashx) os dados são carregados em um córrego, decifrados e enviados para o cliente. Agora isso tem funcionado muito bem até recentemente,

Ele funciona muito bem em todos os navegadores exceto cromo onde o arquivo é baixado como um arquivo .gz e é ilegível?

Eu retirados a busca corrente e peças de criptografia para a brevidade (tenha em mente que isso funciona perfeitamente no IE, Firefox, etc)

    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

Qualquer ajuda seria muito apreciada.

Aqui está o cabeçalho HTTP do violinista quando o arquivo é baixado em cromo

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

Note que o nome do arquivo é codekiwi.txt e os conteúdos são algumas simples de texto simples, o arquivo é salvo como codekiwi.txt.gz e contém rabiscos.

Foi útil?

Solução

Ok, resolvido isso sozinho. I Acontece que Chrome (e Firefox) realmente não gosto dos Response.ClearHeaders chamar, por algum motivo IE estava ok com isso, uma vez que o removeu os downloads funcionou como esperado novo ...

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top