【问题标题】:Cache Manifest with Windows Forms WebBrowser control (Visual Studio)使用 Windows 窗体 WebBrowser 控件缓存清单 (Visual Studio)
【发布时间】:2015-08-28 09:41:03
【问题描述】:

我正在使用 Windows 窗体 WebBrowser 控件来显示我也在编写的 Web 应用程序。 Web 应用程序正在使用 HTML5 Cache Manifest 功能,当我在 Chrome 和 IE (V11) 中调用该页面时,该功能可以正常工作。但是,当我在 WebBrowser 控件中测试缓存清单时,它不起作用。

我的理解是 WebBrowser 控件使用 IE 的最新本地实例进行渲染/处理 - 但是它不喜欢缓存清单功能。我的缓存清单 (cache.appcache) 文件包含以下内容:

CACHE MANIFEST
#V1.6

CACHE:
Default.aspx

NETWORK:


FALLBACK:
Error.aspx

项目的其余部分非常标准。

我确实必须更新 IIS 的 MIME 以识别 appcache 扩展,这已被转换为:text/cache-manifest

任何人都可以为此提供任何帮助,我们将不胜感激!我已经研究了在项目中使用其他 Web Broswer 控件的可能性,但我真的希望让事情尽可能简单......如果可能的话!

谢谢!

【问题讨论】:

    标签: html internet-explorer caching webbrowser-control cache-manifest


    【解决方案1】:

    我也遇到了同样的问题,不确定您是否找到了解决方法?

    我注意到 webbrowser 控件创建了 Internet 临时文件 (C:\Users\[USER]\AppData\Local\Microsoft\Windows\Temporary Internet Files)

    而原生 IE11 浏览器没有,所以看起来临时文件胜过 appcache.. 如果我在 aspx 页面中设置了 no-cache 元标记,那么 appcache 停止工作.. 我一直整个星期都在转圈!

    无论如何,我会继续寻找,如果找到答案,请确保发布答案。

    【讨论】:

    • 我通过在 WPF 中开发应用程序,然后使用加密的 WCF Web 服务检索数据,迅速转向其他方法来实现所需的结果。 WPF 应用程序使用 Click Once 来确保根据需要推出任何更新。到目前为止,这似乎是一个明智的举动!!抱歉 - 但这并没有真正解决问题!
    【解决方案2】:

    知道了! 对于其他可能需要 .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:
    *
    

    【讨论】:

      猜你喜欢
      • 2015-08-09
      • 2010-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-03
      • 1970-01-01
      相关资源
      最近更新 更多