























今天在处理一个图片显示的动态请求路径,为了缓解宽带压力,故增加客户端缓存。
代码很简单如下:
Response.GetTypedHeaders().CacheControl = new CacheControlHeaderValue { Public = true, MaxAge = TimeSpan.FromDays(30) }; //Response.Headers["Cache-Control"] = "public,max-age=2592000"; // 30 天 = 2592000秒
//Response.Headers[Microsoft.Net.Http.Headers.HeaderNames.CacheControl] = "public,max-age=2592000";
var result = PhysicalFile(newFilePath, MimeUtility.GetMimeMapping(newFilePath)); result.EnableRangeProcessing = true; return result;
注意在Visual Studio中调试,注意:如果使用的是 IIS Express不会呈现缓存的效果,IIS Express会处理掉了,也就是返回不会出现 Cache-Control这个关键字,建议使用 Kestrel。
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。