Question

I am following Stephen Walther's guide and everything builds without errors. However once I run the application in Chrome I get this error message:

Application Cache Error event: Failed to parse manifest http://localhost/website/Manifest.ashx

And nothing is cached.

From what I have gathered from here, I have a type-o in my manifest. Maybe you can see something I did wrong and causing this error message.

Manifest.ashx:

<%@ WebHandler Language="C#" Class="JavaScriptReference.Manifest" %>

using System;
using System.Web;

namespace JavaScriptReference {

    public class Manifest : IHttpHandler {

        public void ProcessRequest(HttpContext context) {
            context.Response.ContentType = "text/cache-manifest";
            context.Response.WriteFile(context.Server.MapPath("Manifest.txt"));
        }

        public bool IsReusable {
            get {
                return false;
            }
        }
    }
}

Manifest.txt:

CACHE MANIFEST

CACHE:
Images/img1.jpg
Images/img2.jpg
JScript.js
Default.aspx.vb 
# Does Default.aspx.vb even need to be cached?
Was it helpful?

Solution

TLDR: Don't add a CACHE: entry in your manifest, don't cache code-behind files and make sure you registered the HttpHandler in your Web.Config

Long Version:

There are a few things that you need to do to make the sample app work. First up you create your handler as above, an example in C# is:

using System.Web;

namespace CacheTest
{
    public class Manifest : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/cache-manifest";
            context.Response.WriteFile(context.Server.MapPath("Manifest.txt"));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

Next you need to register the handler in your web.config like:

    <configuration>
        <system.web>        
            <httpHandlers>
                <add verb="*" path="Manifest.ashx" 
                    type="CacheTest.Manifest, CacheTest" />
            </httpHandlers>
        </system.web>
    </configuration>

Next up create a Manifest.txt in the root of your website and populate it. The sample should not have a CACHE: heading inside it. A working sample may look like:

CACHE MANIFEST

# v30

Default.aspx

Images/leaping-gorilla-logo.png

Note that we do not cache code behind files, only relative paths to actual resources that a browser may request. Finally, add a Default.aspx file. Ignore the code behind but edit the markup so that the initial HTML tag references the HttpHandler, the full markup:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CacheTest.Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" manifest="Manifest.ashx">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        This is a sample offline app!
    </div>
    </form>
</body>
</html>

With this done you can now start your website, browse to it in FireFox and you will be asked permission to take it offline. Alternatively, fire it up in Chrome, switch to the developer tools, check the Resources tab and you will be able to see the resources that have been loaded under the Application Cache node:

Offline App running in Google Chrome

And for completeness, your finished code structure will look like:

enter image description here

OTHER TIPS

The error "Application Cache Error event: Failed to parse manifest" can be caused by formatting of the text file.

My deployment script generated the manifest file in Unicode. The file looked fine in Chrome (when going to the URL), validated on online validators, but would generate this error when being used as a manifest.

To fix the file, just open the manifest file in notepad and go to "Save-As" and select UTF8.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top