Html 使用URL图像源的Web浏览器图像缓存
我有一个API,它将存储在远程网站上的图像提供给ASP MVC网站 该网站包含一个带有Get方法的控制器,该方法基于传递的文件名返回图像Html 使用URL图像源的Web浏览器图像缓存,html,asp.net-mvc-5,Html,Asp.net Mvc 5,我有一个API,它将存储在远程网站上的图像提供给ASP MVC网站 该网站包含一个带有Get方法的控制器,该方法基于传递的文件名返回图像 [HttpGet] public ActionResult Get( string fileName ) { byte[] imageBytes = _apiService.GetImage( fileName ); using ( MemoryStream streak = new MemoryStr
[HttpGet]
public ActionResult Get( string fileName )
{
byte[] imageBytes = _apiService.GetImage( fileName );
using ( MemoryStream streak = new MemoryStream( imageBytes ) )
{
return File( streak.ToArray(), string.Format( "image/{0}", Path.GetExtension( fileName ).Replace( ".", "" ) ) );
}
}
然后我使用下面的代码在网页上显示图像
<img class="centred-image item-image img-responsive cateogry-image" src="/Images/Get?fileName=football5.jpg" alt="product">
但是,图像不会缓存在浏览器中,每次刷新都会被请求/传输。如何更改实现以允许图像缓存?如果将此项添加到控制器,会发生什么情况:
[OutputCache(Duration=3600, VaryByParam="none", Location=OutputCacheLocation.Client)]
[HttpGet]
public ActionResult Get( string fileName )
如果将此项添加到控制器,会发生什么情况:
[OutputCache(Duration=3600, VaryByParam="none", Location=OutputCacheLocation.Client)]
[HttpGet]
public ActionResult Get( string fileName )