Пример #1
0
        static void AddFileDependencies(object instance, HttpResponseBase response)
        {
            if (instance is IFileDependent fileDependent)
            {
                string[] files = fileDependent.FileDependencies;

                if (files != null)
                {
                    response.AddFileDependencies(files);
                }
            }
        }
Пример #2
0
    public static DateTime SetCacheHeaders(HttpContextBase context)
    {
        string[]         allFiles     = Directory.GetFiles(context.Server.MapPath("~/"), "*.*", SearchOption.AllDirectories);
        DateTime         lastModified = allFiles.Max(f => File.GetLastWriteTime(f));
        HttpResponseBase response     = context.Response;
        HttpRequestBase  request      = context.Request;

        lastModified = new DateTime(lastModified.Year, lastModified.Month, lastModified.Day, lastModified.Hour, lastModified.Minute, lastModified.Second);

        string incomingDate = request.Headers["If-Modified-Since"];

        response.Cache.SetLastModified(lastModified);

        DateTime testDate = DateTime.MinValue;

        if (DateTime.TryParse(incomingDate, out testDate) && testDate == lastModified)
        {
            response.ClearContent();
            response.StatusCode      = (int)System.Net.HttpStatusCode.NotModified;
            response.SuppressContent = true;
        }

        if (!request.IsLocal)
        {
            response.Cache.SetValidUntilExpires(true);
            response.Cache.SetCacheability(HttpCacheability.Public);
            response.Cache.VaryByParams["path"]            = true;
            response.Cache.VaryByHeaders["X-Content-Only"] = true;
            response.AddFileDependencies(allFiles);
            response.Cache.SetLastModifiedFromFileDependencies();
            response.Cache.SetMaxAge(TimeSpan.FromDays(7));
            response.AppendHeader("Arr-Disable-Session-Affinity", "True");             // For Azure Websites
        }

        return(lastModified);
    }
 public override void AddFileDependencies(string[] filenames)
 {
     _httpResponseBase.AddFileDependencies(filenames);
 }
 public override void AddFileDependencies(ArrayList filenames)
 {
     proxiedResponse.AddFileDependencies(filenames);
 }