缓存清单在MVC4应用程序中不起作用

时间:2014-10-14 14:24:35

标签: html5 asp.net-mvc-4 html5-appcache offline-caching cache-manifest

这是我的CacheManifestHandler。

  

生成的清单文件不会缓存虚拟路径中指定的任何内容。   请仔细阅读代码。生成的清单文件   通过以下代码不包含缓存文件中的项目。

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);
        }
    }
}

布局页面:

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

Web配置:

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

生成缓存清单:

    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

0 个答案:

没有答案