9

I'm in the process of building an asp.net (3.5) web app and was wondering if you knew of any way I could do it so that there would be some offline functionality.

This is needed as people will be able to 'install' the web app on their device (using the 'Add to home screen' function on an iPhone for example) and then use the app when they are offline; the usage would only be limited (there would be no need for server calls at this point either).

Can this be done with an .aspx page?

Edit- .manifest added:

CACHE MANIFEST
index.aspx

/logo.png
/main.css
/main.js

Edit no.2-

We have it working offline, in a fashion; it works when in safari but we don't want it in safari, we want it as a standalone app. When we try to run it like this we get the 'can't connect to server error'. Is this possible with a .aspx page?

Edit no.3 -

We've got this to work using a .html page but still not yet with an .aspx

Edit no.4-

It's now working, although we're unsure why! We added the index.aspx to the 'network' section of the cache.manifest last week (which didn't work last week!) which may have helped but once I know for sure I'll update you with what actually happened!

Thanks to all for your help!

4

4 回答 4

14

对于使用 ASP.NET 的离线 HTML5 应用程序,请参阅此链接和此链接

对于离线功能,有一些替代方案:

01 - 如果你需要在离线应用中存储少量数据,并且安全不是一个大问题,你可以使用HTML5 Web Storage(链接链接链接链接链接,看看CanIUse for 了解浏览器版本支持)。

主要缺点是它缺乏安全性,是基于键值的(没有复杂的结构),并且存储大小有很大的限制(大多数浏览器为 5MB)。


02 - 如果您需要更大的数据量,您可以查看IndexDB(链接链接链接CanIUse)或Web Sql(链接链接链接CanIUse,用于浏览器支持)。

Web SQL 的主要缺点是 Firefox 和 IE 不支持它。此外,它已被 W3C 弃用。

IndexDB 很好(链接),但似乎 ios 仍然不支持它(参见 canIUse)。

对于方法 1 和 2,您可以在 ASP.NET 应用程序中进行响应式设计或专用移动网站(链接)。


03 - (更大的灵活性需要更多的努力)在您的 ASP.NET 应用程序中实现一个 Web 服务和一个应用偶尔连接的应用程序概念的移动本机应用程序(更多信息:链接链接

  • ASP.NET Web 应用程序=> 对于 Web 应用程序,公开一个具有与离线功能相关的服务的 Web 服务。

  • 移动应用程序=> 实现一个本地移动应用程序(例如,为 android 和 iphone 开发一个应用程序),并为应用程序提供一个数据库。然后,您在移动应用程序中创建离线功能,该功能将使用自己的数据库来读取和写入(本地)必须离线可用的数据。

然后,您在依赖于 Internet(例如循环线程)的移动应用程序中实现静默同步机制,该机制将通过 Web 服务访问 ASP.NET 应用程序来搜索更新。这种同步机制将发送本地存储的数据并从 Web 服务中恢复可用于离线功能的数据。


希望能帮助到你。

于 2013-08-07T12:21:28.657 回答
1

是的。正如其他人所说,这可以使用缓存清单来完成。

我建议做的是创建一个处理程序来生成缓存清单,它可以是动态的。

缓存清单文件令人痛苦的一件事是,除非该文件更改,否则不会发生更新。这是处理程序的用武之地。添加带有 # 作为注释字符的注释部分,然后更新时间戳

#2013-08-08 1:53:36 PM 'This is your comment section

如果这是由处理程序生成的,您可以在每个用户的页面可能已更新时将其存储在数据库中(这使其在仍然缓存的同时保持动态)

使用缓存清单时要记住的一件重要事情:

缓存的文件必须与被访问的文件的确切查询字符串匹配。这在某些设备上似乎区分大小写,并且存在于一个设备上的任何查询字符串必须在另一个设备上完全相同,因此在生成缓存清单文件时需要这种远见。

于 2013-08-07T13:28:53.417 回答
1

一种方法——虽然我还没有机会真正做到这一点——是使用 HTML5 的新特性之一:缓存清单。

你可以在这里阅读一个很好的例子:http: //www.html5rocks.com/en/tutorials/appcache/beginner/

于 2013-08-07T11:24:26.627 回答
0

是的,这可以通过 ASP.NET 完成,因为 ASP.NET 在客户端浏览器中呈现为 HTML 页面,而离线功能是纯 JavaScript/Html 功能。是 Stephen Walther 的一篇文章,展示了一种方法。

于 2013-08-07T11:23:50.423 回答