我正在关注Stephen Walther's指南和一切构建都没有错误。但是,一旦我在 Chrome 中运行该应用程序,我就会收到以下错误消息:
Application Cache Error event: Failed to parse manifest http://localhost/website/Manifest.ashx
并且没有缓存任何内容。
根据我从 here 收集到的信息,我的 list 中有一个 type-o。也许您可以看到我做错了什么并导致此错误消息。
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?
最佳答案
TLDR: 不要在 list 中添加 CACHE: 条目,不要缓存代码隐藏文件,并确保在 Web.Config 中注册了 HttpHandler
长版:
要使示例应用程序正常运行,您需要执行一些操作。首先,您按照上面的方式创建处理程序,C# 中的示例如下:
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;
}
}
}
}
接下来,您需要在 web.config 中注册处理程序,如下所示:
<configuration>
<system.web>
<httpHandlers>
<add verb="*" path="Manifest.ashx"
type="CacheTest.Manifest, CacheTest" />
</httpHandlers>
</system.web>
</configuration>
接下来在网站的根目录中创建一个 Manifest.txt 并填充它。示例中不应包含 CACHE: 标题。工作示例可能如下所示:
CACHE MANIFEST
# v30
Default.aspx
Images/leaping-gorilla-logo.png
请注意,我们不会缓存文件后面的代码,仅缓存浏览器可能请求的实际资源的相对路径。最后,添加一个 Default.aspx 文件。忽略后面的代码,但编辑标记,以便初始 HTML 标记引用 HttpHandler,完整标记:
<%@ 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>
完成此操作后,您现在可以启动您的网站,在 FireFox 中浏览该网站,系统会询问您是否允许其离线。或者,在 Chrome 中启动它,切换到开发者工具,检查“资源”选项卡,您将能够看到“应用程序缓存”节点下已加载的资源:
为了完整性,您完成的代码结构将如下所示:
关于asp.net - 无法解析 list : Using asp.net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11690896/