コード例 #1
0
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            HttpCachePolicyBase cache = filterContext.HttpContext.Response.Cache;

            cache.SetCacheability(HttpCacheability.NoCache);
            cache.SetExpires(DateTime.Now);
            cache.SetAllowResponseInBrowserHistory(false);
            cache.SetNoServerCaching();
            cache.SetNoStore();
        }
コード例 #2
0
        private static void PrepareResponseNoCache(HttpResponseBase response)
        {
            HttpCachePolicyBase cachePolicy = response.Cache;
            DateTime            now         = DateTime.Now;

            cachePolicy.SetCacheability(HttpCacheability.Public);
            cachePolicy.SetExpires(now + TimeSpan.FromDays(365));
            cachePolicy.SetValidUntilExpires(true);
            cachePolicy.SetLastModified(now);
            cachePolicy.SetNoServerCaching();
        }
コード例 #3
0
 /// <summary>
 /// It is better to detect controller and action rather than plain url (such as "/Home/Index", "/Home", "/" since routes are equal by default).
 /// </summary>
 public void DetectConfiguration(string url, HttpCachePolicyBase cachePolicy)
 {
     if (url == "/CodeCaching/Index")
     {
         cachePolicy.SetNoServerCaching();
         cachePolicy.SetCacheability(HttpCacheability.NoCache);
     }
     else
     {
         cachePolicy.SetExpires(DateTime.Now.AddSeconds(30));
         cachePolicy.SetCacheability(HttpCacheability.Public);
     }
 }
コード例 #4
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();
            }
        }