Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

280
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda