Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

281
Visualizações
Content-Disposition is always null

I've a got a function in my web api 2.0 to download a file but hadn't tried it in a while and only discovered yesterday that it was no longer working. I've partially fixed the issue with createObjectURL but one thing I've noticed is that while the Content-Disposition is set in my web api:

public Task<HttpResponseMessage> ExecuteAsync(CancellationToken cancellationToken)
{
    var response = new HttpResponseMessage();
    var filename = this.Document.GetFilename();
    var mimeType = MimeMapping.GetMimeMapping(filename);
    
    response.Content = new StreamContent(new MemoryStream(this.Document.ToData()));     
    response.Content.Headers.ContentLength = this.Document.Data.Length;     
    response.Content.Headers.ContentType = new MediaTypeHeaderValue(mimeType);

    response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
    {
        FileName = filename
    };

    return Task.FromResult(response);
}

Yet when I check it in JavaScript, it always null from the response header:

success: function (blob, status, xhr) {
   var filename = "";
   var disposition = xhr.getResponseHeader('Content-Disposition');
   ...
}

Any ideas why?

Thanks.

UPDATE-1:

The content disposition appears to be returned when I check the response in the Network section of the browser but when I call xhr.getAllResponseHeaders() or xhr.getResponseHeader('Content-Disposition');, it is not returned by either function calls as you can see in the snapshot below:

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I just figured out the problem and it was of my own doing unfortunately!!

I had the following in my ajax request:

xhrFields: {
    responseType: 'blob' 
}

but then I introduced credentials support and introduce this

xhrFields: {
    withCredentials: true
}

but I didn't spot this until this morning when I realized I stupidly declared as above clearly i.e. 2 statements, thus, overwriting the responseType: 'blob' setting when I should have declared it as:

xhrFields: {
    responseType: 'blob',
    withCredentials: true
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda