4

Here is my CacheManifestHandler.

Manifest file generated doesn't cache any thing that is specified in virtual path. Kindly review the code. Manifest file generated by the below code does not contain the items in cache file.

public class CacheManifestHandler : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/cache-manifest";
        context.Response.Write("CACHE MANIFEST" + Environment.NewLine);
        context.Response.Write("CACHE:" + Environment.NewLine);

        WriteBundle(context, "~/bundles/jqueryval");
        WriteBundle(context, "~/bundles/modernizr");

        context.Response.Write(System.Web.Optimization.Scripts.Url("~/Images/orderedList1.png") + Environment.NewLine);
        context.Response.Write(System.Web.Optimization.Scripts.Url("~/Images/orderedList2.png") + Environment.NewLine);
        context.Response.Write(System.Web.Optimization.Scripts.Url("~/Images/orderedList3.png") + Environment.NewLine);
        context.Response.Write(System.Web.Optimization.Scripts.Url("~/Images/orderedList8.png") + Environment.NewLine);
        context.Response.Write(System.Web.Optimization.Scripts.Url("~/Images/orderedList9.png") + Environment.NewLine);

        context.Response.Write("NETWORK:" + Environment.NewLine);
        context.Response.Write("*" + Environment.NewLine);

        if (IsDebug) 
            context.Response.Write(Environment.NewLine + DateTime.Now.ToLongTimeString());
    }

    private void WriteBundle(HttpContext context, string virtualPath)
    {
        if (IsDebug)
        {
            foreach (string contentVirtualPath in System.Web.Optimization.BundleResolver.Current.GetBundleContents(virtualPath))
            {
                context.Response.Write(Scripts.Url(contentVirtualPath).ToString() + Environment.NewLine);
            }
        }
        else
        {
            context.Response.Write(System.Web.Optimization.Scripts.Url(virtualPath).ToString() + Environment.NewLine);
        }
    }
}

Layout Page:

<!DOCTYPE html><html manifest="cache.manifest"></html>

Web Config:

    <httpHandlers>
  <add verb="GET"  path="cache.manifest"     
 type="SampleCacheManifest.Models.CacheManifestHandler" />
  </httpHandlers>

Cache manifest generated:

    CACHE MANIFEST
    CACHE:
   /Scripts/jquery.mobile-1.4.2.js
   /Scripts/jquery-2.1.1.js
   /Scripts/jquery-ui-1.10.4.js
   /Scripts/jquery.unobtrusive-ajax.js
   /Scripts/Hwy905Scripts/Hwy905Custom.js
   /Scripts/Hwy905Scripts/CheckInventory.js
   /Scripts/Hwy905Scripts/CycleCount.js
   /Scripts/Hwy905Scripts/DirectedPickingSearch.js
   /Scripts/Hwy905Scripts/DirectedPutaway.js
   /Scripts/Hwy905Scripts/ManualPickingSearch.js
   /Scripts/Hwy905Scripts/Hwy905SerialNumberCapture.js
   /Scripts/Hwy905Scripts/UnitToUnit.js
   /Images/accent.png
   /Images/bullet.png
   /Content/HwyImages/Highway905Bg_1.jpg
   /Content/HwyImages/Highway905Bg_1.png
   NETWORK:
   *

   5:07:24 AM
Vivek Ranjan
  • 1,432
  • 2
  • 15
  • 37

0 Answers0