【发布时间】:2014-03-18 06:53:06
【问题描述】:
我有一个包含多个 C# 项目的应用程序,如下所示
- CRM.DomainLogic
- CRM.Web
- Warehouse.DomainLogic
- Warehouse.Web
- ,...
每个 web 项目(例如 CRM.Web)都有自己的“html 视图”和“js 控制器” 还有其他几种静态文件。
为了使部署更容易,我想使用 Html5 清单。
因此,为了使跨项目的单独部署成为可能,我使用了 iframe。 由于CRM.Web的变化,客户将获得CRM文件,无需再次下载Warehouse.Web文件!
步骤:
1- 我有一个返回 Web 程序集的所有名称的 Web API 方法,例如 CRM.Web 和 Warehouse.Web
2- 我有另一个 Web API 方法,它获取程序集名称作为参数并返回指向位于该项目上的文件的清单文件内容。
public HttpResponseMessage GetManifestByAssemblyName(String assemblyName)
此处省略代码。
response.Content = new StringContent(manifestBody.ToString(), Encoding.UTF8, "text/cache-manifest");
3- 在客户端,我为每个程序集创建一个新的 iFrame,并将 src 设置为另一个返回 html 正文的 Web api 方法,它的清单被分配给返回清单正文的 WebAPI 方法的地址(GetManifestByAssemblyName)
String result = String.Format
(@"<html manifest='{0}'> </html>", "/api/AppManifest/GetManifestByAssemblyName?assemblyName=" + assemblyName + ".manifest");
response.Content = new StringContent(result, UTF8Encoding.Default, "text/html");
iFrames的代码:
var htmlPageUrl = "/api/AppManifest/GetHtmlContainerForManifestByName?assemblyName=" + name;
var iFrame = document.createElement("iFrame");
iFrame.setAttribute("src", htmlPageUrl);
iFrame.setAttribute("sandbox", "allow-same-origin");
iFrame.setAttribute("seamless", "seamless");
document.body.appendChild(iFrame);
当我运行应用程序时,它会获取程序集名称,然后创建 iFrame,每个 iFrame 都会自动获取自己的清单。
但是window.applicationCache.status 为0,表示没有缓存。
当我进入资源页面时,我可以看到以下内容:
但是当我请求其中一个被缓存的文件时,该请求不会使用缓存。
我知道我在网络上的工作没有参考,这完全基于我的想法,我知道这里可能会出现一些安全限制,但是有什么解决方案可以解决问题吗?
提前致谢。
注意:You can download sample application source code here.
然后按Ctrl+S保存文件,并先阅读Index.html注释。
【问题讨论】:
标签: c# html iframe cache-manifest