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 7193319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:08:47+00:00 2026-05-28T20:08:47+00:00

I have an actionmethod that returns a File and has only one argument (an

  • 0

I have an actionmethod that returns a File and has only one argument (an id).

e.g.

public ActionResult Icon(long id)
{
    return File(Server.MapPath("~/Content/Images/image" + id + ".png"), "image/png");
}

I want the browser to automatically cache this image the first time I access it so the next time it doesn’t have to download all the data.

I have tried using things like the OutputCacheAttribute and manually setting headers on the response. i.e:

[OutputCache(Duration = 360000)]

or

Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetExpires(Cache.NoAbsoluteExpiration); 

But the image is still loaded every time I hit F5 on the browser (I’m trying it on Chrome and IE). (I know it is loaded every time because if I change the image it also changes in the browser).

I see that the HTTP response has some headers that apparently should work:

Cache-Control:public, max-age=360000

Content-Length:39317

Content-Type:image/png

Date:Tue, 31 Jan 2012 23:20:57 GMT

Expires:Sun, 05 Feb 2012 03:20:56 GMT

Last-Modified:Tue, 31 Jan 2012 23:20:56 GMT

But the request headers have this:

Pragma:no-cache

Any idea on how to do this?

Thanks a lot

  • 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-05-28T20:08:48+00:00Added an answer on May 28, 2026 at 8:08 pm

    First thing to note is that when you hit F5 (refresh) in Chrome, Safari or IE the images will be requested again, even if they’ve been cached in the browser.

    To tell the browser that it doesn’t need to download the image again you’ll need to return a 304 response with no content, as per below.

    Response.StatusCode = 304;
    Response.StatusDescription = "Not Modified";
    Response.AddHeader("Content-Length", "0");
    

    You’ll want to check the If-Modified-Since request header before returning the 304 response though. So you’ll need to check the If-Modified-Since date against the modified date of your image resource (whether this be from the file or stored in the database, etc). If the file hasn’t changed then return the 304, otherwise return with the image (resource).

    Here are some good examples of implementing this functionality (these are for a HttpHandler but the same principles can be applied to the MVC action method)

    • Make your browser cache the output of a httphandler
    • HTTP Handler implementing dynamic resource caching
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an MVC controller that has this Action Method: [HttpPost] public ActionResult SubmitAction()
I have a controller that sets TempData before returning a view, public ActionResult Edit(int
I have the following action method that returns a collection of AdminDetail instances: public
I have an action method that depending on some conditions needs to return a
I have a controller that handles file uploads. Ultimately I would like to be
I have a Controller bean (SearchController) that has two managed bean as managed properties
I have an Action Method that returns a JSON-serialized object. The problem I'm having
I have a website that uses one Action method which passes a pagename to
I have some jQuery code in an external Javascript file that is making an
I have a Create ActionMethod, something along the lines of: [AcceptVerbs(HttpVerbs.Post)] public ActionMethod Create(Journey

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.