知道了!
对于其他可能需要 .net webcontrol 中的 appcache 帮助的人。
下面的代码是我正在测试的示例。
代码涵盖了aspx页面、javascript、webconfig和appcache文件。
javascript 也有一些事件处理程序来显示其进度。
aspx 页面中的元标记是一个关键角色 - 没有它,它就无法工作。
不要忘记,appcache 的本质是在您第一次访问该站点时下载更改,然后在下次访问时显示更改。如果您愿意,您可以拦截任何更改并通过事件处理程序自动显示。
还有其他让我感到困惑的事情,避免使用 localhost 访问页面,(似乎只是 chrome 中的问题),appcache 的工作方式似乎不同.. 你真的想使用 IP 地址:
例如:
不要使用:http://localhost/web/index.aspx
使用:http://10.1.1.4/web/index.aspx
最后一件事 - 文件名区分大小写!
我注意到 appcache 内容依赖于确切的大小写 - 所以我只是确保我的所有文件都是小写的。 (appcache 文件、aspx、js、图片,应有尽有!)
希望它有所帮助 - 祝大家好运!
#### ASPX Page (file: index.aspx) #####
<html manifest="index.appcache">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title></title>
</head>
<body>
<div>index.aspx--v1</div>
<img src="./images/data_replace.png" />
<textarea id="Textarea1"
style="position: absolute; font-family: Arial; font-size: 10pt;
width: 277px; height: 360px; margin-top: 2px; text-align: left; top: 103px; left: 18px; z-index:1000;"></textarea>
</body>
<script type="text/javascript" src="index.js"></script>
</html>
###### JavaScript (file: index.js) ######
function $get(id) {
return document.getElementById(id);
}
function fnLoad() {
setTimeout(function () { alert("hello"); }, 1000);
if (window.applicationCache) {
var appCache = window.applicationCache;
appCache.addEventListener('error', appCacheError, false);
appCache.addEventListener('checking', checkingEvent, false);
appCache.addEventListener('noupdate', noUpdateEvent, false);
appCache.addEventListener('downloading', downloadingEvent, false);
appCache.addEventListener('progress', progressEvent, false);
appCache.addEventListener('updateready', updateReadyEvent, false);
appCache.addEventListener('cached', cachedEvent, false);
}
function appCacheError() { $get('Textarea1').value = $get('Textarea1').value + "\nerror" }
function checkingEvent() { $get('Textarea1').value = $get('Textarea1').value + "\nchecking" }
function noUpdateEvent() { $get('Textarea1').value = $get('Textarea1').value + "\nnoupdate" }
function downloadingEvent() { $get('Textarea1').value = $get('Textarea1').value + "\ndownloading" }
function progressEvent() { $get('Textarea1').value = $get('Textarea1').value + "\nprogress" }
function updateReadyEvent() { $get('Textarea1').value = $get('Textarea1').value + "\nupdateready" }
function cachedEvent() { $get('Textarea1').value = $get('Textarea1').value + "\ncached" }
}
fnLoad();
#### Web.Config #####
<system.webServer>
<staticContent>
<mimeMap fileExtension=".appcache" mimeType="text/cache-manifest"/>
</staticContent>
</system.webServer>
#### Appcache File (file: index.appcache) ####
CACHE MANIFEST
# v1.1
CACHE:
index.js
images/data_replace.png
NETWORK:
*