Web API 输出文件缓存

            var httpMsg = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new ByteArrayContent(fileData)
            };
            httpMsg.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
            httpMsg.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
            {
                FileName = HttpUtility.UrlEncode(attachment.FileName).Replace("+", "%20")
            };
            httpMsg.Content.Headers.Expires = DateTimeOffset.MaxValue;
            httpMsg.Headers.ETag = new EntityTagHeaderValue("\"NoChange\"");
            httpMsg.Headers.CacheControl = new CacheControlHeaderValue()
            {
                MaxAge = TimeSpan.FromDays(365),
                Public = true,
            };
            return ResponseMessage(httpMsg);
            if (Request.Headers.IfNoneMatch.Any())
            {
                return ResponseMessage(new HttpResponseMessage(HttpStatusCode.NotModified));
            }

 

posted on 2017-09-13 08:36  木龙哥  阅读(222)  评论(0编辑  收藏  举报

导航