Пример #1
0
        /// <summary>
        /// action执行后
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            if (this._MaxSecond <= 0)
            {
                return;
            }

            HttpCachePolicyBase cache         = filterContext.HttpContext.Response.Cache;
            TimeSpan            cacheDuration = TimeSpan.FromSeconds(this._MaxSecond);

            cache.SetCacheability(HttpCacheability.Public);
            //cache.SetLastModified(DateTime.Now.AddHours(8).Add(cacheDuration));
            //cache.SetExpires(DateTime.Now.AddHours(8).Add(cacheDuration));//GMT时间 格林威治时间
            cache.SetExpires(DateTime.Now.Add(cacheDuration));
            cache.SetMaxAge(cacheDuration);
            cache.AppendCacheExtension("must-revalidate, proxy-revalidate");
        }
Пример #2
0
 public override void OnActionExecuted(ActionExecutedContext filterContext)
 {
     // Client-side caching?
     if (CachePolicy == CachePolicy.Client || CachePolicy == CachePolicy.ClientAndServer)
     {
         if (Duration <= 0)
         {
             return;
         }
         HttpCachePolicyBase cache         = filterContext.HttpContext.Response.Cache;
         TimeSpan            cacheDuration = TimeSpan.FromSeconds(Duration);
         cache.SetCacheability(HttpCacheability.Public);
         cache.SetExpires(DateTime.Now.Add(cacheDuration));
         cache.SetMaxAge(cacheDuration);
         cache.AppendCacheExtension("must-revalidate, proxy-revalidate");
     }
 }
Пример #3
0
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            if (Duration <= 0)
            {
                return;
            }

            HttpCachePolicyBase cache         = filterContext.HttpContext.Response.Cache;
            TimeSpan            cacheDuration = TimeSpan.FromSeconds(Duration);

            cache.SetNoStore();
            cache.SetCacheability(HttpCacheability.NoCache);
            cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
            cache.AppendCacheExtension("post-check=0, pre-check=0");
            //cache.SetVaryByCustom("lang");
            //cache.SetExpires(DateTime.Now.Add(cacheDuration));
            //cache.SetMaxAge(cacheDuration);
        }
Пример #4
0
        public override void OnResultExecuting(ResultExecutingContext filterContext)
        {
            if (filterContext.IsChildAction)
            {
                return;
            }

            HttpCachePolicyBase cachePolicy = filterContext.HttpContext.Response.Cache;

            cachePolicy.SetExpires(DateTime.UtcNow.AddDays(-1));
            cachePolicy.SetValidUntilExpires(false);
            //cachePolicy.SetRevalidation(HttpCacheRevalidation.AllCaches);
            cachePolicy.AppendCacheExtension("must-revalidate, proxy-revalidate");
            cachePolicy.SetCacheability(HttpCacheability.NoCache);
            cachePolicy.SetNoStore();

            base.OnResultExecuting(filterContext);
        }
Пример #5
0
        protected override void SendMediaHeaders(Media media, HttpContextBase context)
        {
            GetResponseCacheHeadersArgs args = new GetResponseCacheHeadersArgs(media.MediaData.MediaItem.InnerItem, new ResponseCacheHeaders()
            {
                Vary = this.GetVaryHeader(media, context)
            })
            {
                RequestType = new RequestTypes?(RequestTypes.Media)
            };

            GetResponseCacheHeadersPipeline.Run(args);
            HttpCachePolicyBase cache = context.Response.Cache;

            if (args.CacheHeaders.LastModifiedDate.HasValue)
            {
                cache.SetLastModified(args.CacheHeaders.LastModifiedDate.Value);
            }
            if (!string.IsNullOrEmpty(args.CacheHeaders.ETag))
            {
                cache.SetETag(args.CacheHeaders.ETag);
            }
            if (args.CacheHeaders.Cacheability.HasValue)
            {
                cache.SetCacheability(args.CacheHeaders.Cacheability.Value);
            }
            if (args.CacheHeaders.MaxAge.HasValue)
            {
                cache.SetMaxAge(args.CacheHeaders.MaxAge.Value);
            }
            if (args.CacheHeaders.ExpirationDate.HasValue)
            {
                cache.SetExpires(args.CacheHeaders.ExpirationDate.Value);
            }
            if (!string.IsNullOrEmpty(args.CacheHeaders.CacheExtension))
            {
                cache.AppendCacheExtension(args.CacheHeaders.CacheExtension);
            }
            if (string.IsNullOrEmpty(args.CacheHeaders.Vary))
            {
                return;
            }
            context.Response.AppendHeader("vary", args.CacheHeaders.Vary);
        }
Пример #6
0
        protected override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            if (filterContext.Exception != null)
            {
                return;
            }

            //Cache
            if (Duration <= 0)
            {
                return;
            }

            HttpCachePolicyBase cache         = filterContext.HttpContext.Response.Cache;
            TimeSpan            cacheDuration = TimeSpan.FromSeconds(Duration);

            cache.SetCacheability(HttpCacheability.Public);
            cache.SetExpires(DateTime.Now.Add(cacheDuration));
            cache.SetMaxAge(cacheDuration);
            cache.AppendCacheExtension("must-revalidate, proxy-revalidate");
        }
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            if (this.Duration == 0)
            {
                return;
            }

            HttpCachePolicyBase cache = filterContext.HttpContext.Response.Cache;

            if (this.Duration < 0)
            {
                cache.SetCacheability(HttpCacheability.NoCache);
                cache.SetExpires(DateTime.Now.AddDays(-1));
            }
            else
            {
                TimeSpan cacheDuration = TimeSpan.FromSeconds(this.Duration);
                cache.SetCacheability(HttpCacheability.Public);
                cache.SetExpires(DateTime.Now.Add(cacheDuration));
                cache.SetMaxAge(cacheDuration);
                cache.AppendCacheExtension("must-revalidate, proxy-revalidate");
            }
        }
Пример #8
0
        public string Index(string id)
        {
            HttpCachePolicyBase cache         = HttpContext.Response.Cache;
            TimeSpan            cacheDuration = TimeSpan.FromSeconds(60);

            cache.SetCacheability(HttpCacheability.Public);
            cache.SetExpires(DateTime.Now.Add(cacheDuration));
            cache.SetMaxAge(cacheDuration);
            cache.AppendCacheExtension("must-revalidate, proxy-revalidate");
            Response.ContentType = "text/cache-manifest";
            var model      = new AppCacheViewModel(Url, id);
            var appversion = ConfigurationManager.AppSettings[id];
            var version    = "v=" + appversion + " a=" + typeof(AppCacheController).Assembly.GetName().Version.ToString();

            if (string.IsNullOrEmpty(appversion))
            {
                version = "a=" + typeof(AppCacheController).Assembly.GetName().Version.ToString();
            }

            model.PageComment = id + " cache version : " + version;

            return(RenderRazorViewToString("Index", model));
        }
Пример #9
0
        public void ProcessRequest(HttpContextBase context)
        {
            this._context = context;
            HttpRequestBase  request  = context.Request;
            HttpResponseBase response = context.Response;
            Uri    url = request.Url;
            string str = !(url == (Uri)null) ? url.LocalPath : throw new HttpException(500, BundleTransformer.Core.Resources.Strings.Common_ValueIsNull);

            if (string.IsNullOrWhiteSpace(str))
            {
                throw new HttpException(500, BundleTransformer.Core.Resources.Strings.Common_ValueIsEmpty);
            }
            if (!this._virtualFileSystemWrapper.FileExists(str))
            {
                throw new HttpException(404, string.Format(BundleTransformer.Core.Resources.Strings.Common_FileNotExist, (object)str));
            }
            string bundleVirtualPath = request.QueryString[Common.BundleVirtualPathQueryStringParameterName];

            if (string.IsNullOrWhiteSpace(bundleVirtualPath) && this.IsStaticAsset)
            {
                AssetHandlerBase.ProcessStaticAssetRequest(context);
            }
            else
            {
                string processedAssetContent;
                try
                {
                    processedAssetContent = this.GetProcessedAssetContent(str, bundleVirtualPath);
                }
                catch (HttpException ex)
                {
                    throw;
                }
                catch (AssetTranslationException ex)
                {
                    throw new HttpException(500, ex.Message, (Exception)ex);
                }
                catch (AssetPostProcessingException ex)
                {
                    throw new HttpException(500, ex.Message, (Exception)ex);
                }
                catch (FileNotFoundException ex)
                {
                    throw new HttpException(500, string.Format(BundleTransformer.Core.Resources.Strings.AssetHandler_DependencyNotFound, (object)ex.Message, (object)ex));
                }
                catch (Exception ex)
                {
                    throw new HttpException(500, string.Format(BundleTransformer.Core.Resources.Strings.AssetHandler_UnknownError, (object)ex.Message, (object)ex));
                }
                HttpCachePolicyBase cache = response.Cache;
                if (this._assetHandlerConfig.DisableClientCache)
                {
                    response.StatusCode        = 200;
                    response.StatusDescription = "OK";
                    cache.SetCacheability(HttpCacheability.NoCache);
                    cache.SetExpires(DateTime.UtcNow.AddYears(-1));
                    cache.SetValidUntilExpires(false);
                    cache.SetNoStore();
                    cache.SetNoServerCaching();
                    response.ContentType = this.ContentType;
                    response.Write(processedAssetContent);
                }
                else
                {
                    string assetEtag = AssetHandlerBase.GenerateAssetETag(processedAssetContent);
                    int    num       = AssetHandlerBase.IsETagHeaderChanged(request, assetEtag) ? 1 : 0;
                    if (num != 0)
                    {
                        response.StatusCode        = 200;
                        response.StatusDescription = "OK";
                    }
                    else
                    {
                        response.StatusCode        = 304;
                        response.StatusDescription = "Not Modified";
                        response.AddHeader("Content-Length", "0");
                    }
                    response.AddHeader("X-Asset-Transformation-Powered-By", "Bundle Transformer");
                    cache.SetCacheability(HttpCacheability.Public);
                    cache.SetExpires(DateTime.UtcNow.AddYears(-1));
                    cache.SetValidUntilExpires(true);
                    cache.AppendCacheExtension("must-revalidate");
                    cache.SetNoServerCaching();
                    cache.VaryByHeaders["If-None-Match"] = true;
                    cache.SetETag(assetEtag);
                    if (num != 0)
                    {
                        response.ContentType = this.ContentType;
                        response.Write(processedAssetContent);
                    }
                }
                context.ApplicationInstance.CompleteRequest();
            }
        }