我很难弄清楚如何从 blob 流中缓存图像。
这是我的第一个代码,它可以下载返回的图像文件:
HTML 部分:
<img src="@Url.Action("GetImage", "Asset")?photoId=@SessionData.ProfilePic.PhotoID&type=3"/>
控制器:
public ActionResult GetImage(long photoId, PhotoType type)
{
byte[] img = <Code that fetches image byte from blob stream>;
return File(img, "image/png");
}
但这无法在浏览器中缓存。
我在想,如果 url 看起来像这样:
http://stackoverflow.com/Asset/GetImage/1/2
图像现在可以缓存了吗?
所以我创建了另一条路线:
routes.MapRoute(
"Upload",
"Asset/GetImage/{photoId}/{type}",
new { controller = "Asset", action = "GetImage" }
);
并像这样访问图像:
http://stackoverflow.com/Asset/GetImage/1/2
<img src="http://stackoverflow.com/Asset/GetImage/1/2" />
但我总是得到:
Failed to load resource: the server responded with a status of 404 (Not Found)
现在我的问题是:
- 我是否认为当 url 像这样格式化时,
http://stackoverflow.com/Asset/GetImage/1/2
它现在可以被浏览器缓存? - 为什么我会收到此错误?
Failed to load resource: the server responded with a status of 404 (Not Found)
我的路线有什么问题?
希望有人能帮忙。
编辑
这是我的完整路线:
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";
仍然出现错误Failed to load resource: the server responded with a status of 404 (Not Found)
,可能是什么问题?
编辑2
我使用的元标记列表:
<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" />