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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:26:54+00:00 2026-06-08T23:26:54+00:00

I’m having a hard time figuring out on how to cache the image from

  • 0

I’m having a hard time figuring out on how to cache the image from a blob stream.
This is my first code and it works to download the return the image file:

HTML PART:

<img src="@Url.Action("GetImage", "Asset")?photoId=@SessionData.ProfilePic.PhotoID&type=3"/>  

CONTROLLER:

public ActionResult GetImage(long photoId, PhotoType type)
{   
    byte[] img = <Code that fetches image byte from blob stream>;
    return File(img, "image/png");            
}

But this fail to cache in browser.
I am thinking that if the url seems to be like this:

http://stackoverflow.com/Asset/GetImage/1/2  

the image can now be cache?
So I create another route:

routes.MapRoute(
    "Upload",
    "Asset/GetImage/{photoId}/{type}",
    new { controller = "Asset", action = "GetImage" }
);

and access the image like this:

http://stackoverflow.com/Asset/GetImage/1/2
<img src="http://stackoverflow.com/Asset/GetImage/1/2" />

But I always get:

Failed to load resource: the server responded with a status of 404 (Not Found)   

Now my questions are:

  1. Am I right of thinking that when the url is formatted like this http://stackoverflow.com/Asset/GetImage/1/2 it can now be cache by the browser?
  2. Why do I get this error? Failed to load resource: the server responded with a status of 404 (Not Found) What’s wrong with my route?

Hope someone could help.

EDIT

This is my full Routes:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
    "Upload",
    "Asset/GetImage/{photoId}/{type}",
    new { controller = "Asset", action = "GetImage" }
);

var route = routes.MapRoute(
        "Gallery",
        "",
        new { controller = "Auth", action = "Login" },
        new[] { "Project.Areas.Gallery.Controllers" }
    );

route.DataTokens["area"] = "Gallery";  

And still getting the error Failed to load resource: the server responded with a status of 404 (Not Found) , what could be wrong ?

EDIT2

The list of meta tags I’ve used:

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="description" content="">
<meta name="author" content="">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv="imagetoolbar" content="false">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  • 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-08T23:26:56+00:00Added an answer on June 8, 2026 at 11:26 pm

    The following works for me

    Action Method

    [OutputCache(Duration = 20, VaryByParam = "photoId")]
    public ActionResult GetImage(long photoId, long type)
    {
        byte[] img = System.IO.File.ReadAllBytes(Server.MapPath("~/Images/aspNetHome.png"));
        return File(img, "image/png");
    }
    

    HTML

    <img src="~/Home/GetImage/1/2" alt="" />
    

    Route added to Global asax

    routes.MapRoute(
        "Upload",
        "Home/GetImage/{photoId}/{type}",
        new { controller = "Home", action = "GetImage" }
    );
    

    Response headers from Fiddler

    Referer: http:// localhost /MvcApplicationImageTest/Home/GetImage/1/2*

    HTTP/1.1 200 OK
    Cache-Control: private, max-age=20
    Content-Type: image/png
    Expires: Wed, 01 Aug 2012 05:08:25 GMT
    Last-Modified: Wed, 01 Aug 2012 05:08:05 GMT
    Server: Microsoft-IIS/7.5
    X-AspNetMvc-Version: 4.0
    X-AspNet-Version: 4.0.30319
    X-Powered-By: ASP.NET
    Date: Wed, 01 Aug 2012 05:08:10 GMT
    Content-Length: 3736
    

    EDIT following comments

    OutputCacheAttribute removed

    HTTP/1.1 200 OK
    Cache-Control: private
    Content-Type: image/png
    Server: Microsoft-IIS/7.5
    X-AspNetMvc-Version: 4.0
    X-AspNet-Version: 4.0.30319
    X-Powered-By: ASP.NET
    Date: Thu, 02 Aug 2012 04:52:02 GMT
    Content-Length: 3736
    

    As you can see in the headers, Cache-Control just shows private and not Cache-Control: no-cache, Expires: -1, Pragma: no-cache

    I now believe you must be explicitly disabling the cache somehow? Do you have any META tags in your view or layout pages? eg

    <meta http-equiv="cache-control" content="no-cache" />
    
    <meta http-equiv="pragma" content="no-cache" />
    
    <meta http-equiv="expires" content="-1" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I know there's a lot of other questions out there that deal with this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.