Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8648149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:14:51+00:00 2026-06-12T13:14:51+00:00

I have a ASP.NET MVC 4 application with Web API. It’s working great. But

  • 0

I have a ASP.NET MVC 4 application with Web API. It’s working great. But one problem is that IE can’t download a file from a web api while chrome and firefox can. The browser says

"Unable to open this internet site. The requested site is either unavailable or cannot be found."

According to IE 8 and client-side caching, it looks like that no-cache setting causes the problem. So I want to set private cache in that download. But in MVC 4, I found there is no property “Cache” in HttpResponseMessage nor any way to set private cache. Could anybody show how to do this?

Update 1: According to my debugging, it was not cache, but `ContentDisposition’ in following code.

            HttpResponseMessage response = new HttpResponseMessage();
            response.StatusCode = HttpStatusCode.OK;
            response.Content = new StreamContent(result);
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.ms-excel");
//            response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
//              {
//                FileName = "PY75.xls"
//              };
            return response;

If I commented like above, IE can download the file with id as its default file name but it cannot like what described above when uncommenting above. Any idea how to fix this problem? Why IE can’t recognize content-disposition header?

Update 2: After upgrading IE 9, content-disposition is finally working and can download from web api.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:14:52+00:00Added an answer on June 12, 2026 at 1:14 pm

    Try adding

    response.AddHeader("Content-Disposition", "attachment; filename=PY75.xls");
    

    Update

    I looked more into this and it may be a result of the way you’re opening and closing your streams (not sure without seeing the rest of the code. I tried the following and it worked for me, maybe it will work for you!

        public HttpResponseMessage Get()
        {
            string path = @"PATH_TO_XLS";
            MemoryStream responseStream = new MemoryStream();
    
            using (Stream fileStream = File.Open(path, FileMode.Open))
            {
                fileStream.CopyTo(responseStream);
                fileStream.Close();
            }
    
            responseStream.Position = 0;
    
            HttpResponseMessage response = new HttpResponseMessage();
            response.StatusCode = HttpStatusCode.OK;
            response.Content = new StreamContent(responseStream);
            response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = "PY75.xls" };
    
            return response;
        }
    

    The only time I noticed that the browsers would have issues is when the memory stream was closed before sending the response back, which would make sense as the memory stream has to be open to stream the content back to the client. However I noticed the problem on all browsers not just IE. I’m not sure how the rest of your code is handling that, but if you for example handle creating the stream differently for chunked http vs just sending the whole file that could cause it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a layered web application that I built with ASP.NET MVC 4, WebAPI
I have an Asp.Net MVC application that works in the vs.net development web server.
Assuming I have a ASP.NET MVC 3 application that runs in a web farm
I have one question; In my ASP.NET MVC web application have to do certain
I have an ASP.NET MVC web application that implements a custom membership provider. The
I have one doubt here , I have one asp.net MVC web application and
I currently have a ASP.Net MVC web application that needs to upload large files
I have an Asp.Net MVC Web Application that I am developing. I have TeamCity
I have an ASP.NET MVC 4 application which uses the new ASP.NET Web API.
I have an ASP.NET MVC web application that makes REST style web service calls

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.