Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

283
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!