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:
- 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? - 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" />