如何编写AJAX / ASP.NET Web应用程序的脱机版本

时间:2023-01-19 22:30:30

We have a web application that uses AJAX to talk to an ASP.NET web service. We would like to write another version that can be used offline. We need to be able to re-use our existing code as much as possible. What approaches should we consider?

我们有一个使用AJAX与ASP.NET Web服务通信的Web应用程序。我们想写另一个可以离线使用的版本。我们需要能够尽可能地重用现有代码。我们应该考虑哪些方法?


The app is currently using XmlHttpRequest to get dynamic data from the server. Obviously the offline version will not be able to talk to the server, but it does need to talk to something! I'm sure installing IIS or Cassini on the client would work, but I was hoping for a simpler solution. Is there no other way for JavaScript to talk to some external code?

该应用程序当前正在使用XmlHttpRequest从服务器获取动态数据。显然离线版本将无法与服务器通信,但它确实需要与某些东西交谈!我确信在客户端安装IIS或Cassini会起作用,但我希望有一个更简单的解决方案。 JavaScript是否没有其他方式可以与某些外部代码对话?

9 个解决方案

#1


There are plenty offline web apps nowaday. It simply evolve from AJAX.

现在有很多离线网络应用程序。它只是从AJAX演变而来。

For example:

WoaS (wiki on a stick / stickwiki), Tiddly Wiki,

WoaS(棍子上的维基/ stickwiki),Tiddly Wiki,

Google doc and Gmail is going to be offline.

Google文档和Gmail将脱机。

You don't need a webserver to run these webapps in offline mode. Just store the required data, scripts on the client side (usually as XML).

您不需要Web服务器即可在脱机模式下运行这些Web应用程序。只需在客户端存储所需的数据,脚本(通常为XML)。

#2


One of the possibilities would be to use Cassini. This is a web server that acts as a host for the ASP.Net runtime. You can host Cassini in a Windows application or a Windows Service. In this scenario you do not have to rewrite the web app and the web service.

其中一种可能性是使用卡西尼号。这是一个Web服务器,充当ASP.Net运行时的主机。您可以在Windows应用程序或Windows服务中托管Cassini。在这种情况下,您不必重写Web应用程序和Web服务。

Most other solutions do require a rewrite of both your web app and your web service. Depending on the way you have written the existing app you can reuse more or less code.

大多数其他解决方案都需要重写您的Web应用程序和Web服务。根据您编写现有应用程序的方式,您可以重复使用更多或更少的代码。

#3


Have you considered HTML5 with application cache and offline storage?

您是否考虑过具有应用程序缓存和离线存储的HTML5?

#4


If you hope to create an "offline" version of your package your biggest issue by far will be the need to install your site into a local copy of IIS (registering a virtual directory, etc.). I pursued this briefly a few years ago and gave up in frustration. It can be done: a number of software vendors such as DevExpress do this so you have local copies of their demonstration projects. Indeed, I was able to do this. The problem was the classic "it works on my computer" syndrome. There was simply no way to guarantee that most of my end-users had anywhere near the technical proficiency to make this work.

如果您希望创建程序包的“离线”版本,那么到目前为止最大的问题是需要将您的站点安装到IIS的本地副本(注册虚拟目录等)。几年前我曾短暂地追求这一点并且沮丧地放弃了。可以这样做:许多软件供应商(如DevExpress)都这样做,因此您可以获得其示范项目的本地副本。的确,我能够做到这一点。问题是经典的“它适用于我的电脑”综合症。根本没有办法保证我的大多数最终用户都具备接近技术熟练程度的能力。

Thus, I would strongly recommend that you not pursue this path unless you have very technically proficient users and a huge support staff.

因此,我强烈建议您不要追求这条道路,除非您拥有技术熟练的用户和庞大的支持人员。

But there is one more very important question: did you abstract all data access code to a DAL? If not, then you have a lot of work to do in managing data access as well.

但还有一个非常重要的问题:您是否将所有数据访问代码抽象为DAL?如果没有,那么您在管理数据访问方面还有很多工作要做。

Update: user "Rine" has recommended Cassini. I just wanted to let you know that I pursued Cassini and another 3rd-party web server as well. I think that there are licensing issues with Cassini but may be wrong - it has been awhile. However, I do distinctly remember running into barrier after barrier with this approach and very little documentation to help me out.

更新:用户“Rine”推荐了Cassini。我只是想让你知道我追求的是Cassini和另一个第三方网络服务器。我认为卡西尼存在许可问题,但可能是错误的 - 它已经有一段时间了。但是,我确实清楚地记得在使用这种方法进入障碍后进入屏障并且很少有文档来帮助我。

#5


if you want a web application run offline, you need a webserver (IIS for ASP) bound to the localhost (127.0.0.1) address. After this so can access your web application by typing http://127.0.0.1/ in your web browser the same way as you do online.

如果您希望Web应用程序脱机运行,则需要绑定到localhost(127.0.0.1)地址的Web服务器(IIS for ASP)。在此之后,可以通过在Web浏览器中键入http://127.0.0.1/来访问Web应用程序,方法与在线操作相同。

#6


If your AJAX relies on XMLHttpRequest's, you can:

如果您的AJAX依赖于XMLHttpRequest,您可以:

  1. Make the static versions of XML's you get over XMLHttpRequest and put then into a folder on disk.
  2. 创建XML的静态版本,然后将其放在XMLHttpRequest上,然后放入磁盘上的文件夹中。

  3. Rewrite your XMLHttpRequest URL's so that they point to files on disk.
  4. 重写您的XMLHttpRequest URL,以便它们指向磁盘上的文件。

  5. Rewrite your XMLHttpRequest's so that they don't check status (it's always 0 for the file:// protocol.
  6. 重写您的XMLHttpRequest,以便它们不检查状态(对于file://协议,它总是为0)。

All JScript works on file:// pages as well as on http:// ones.

所有JScript都可以在file:// pages以及http:// ones上运行。

Of course it's not the best way to develop static pages, but it may save you some time on rewriting.

当然,这不是开发静态页面的最佳方式,但它可以为您节省一些重写时间。

#7


I havent come across any framework specifically built for asp.net like the ones available for PHP or RoR. Here is a good article by Steven to get you started with HTML 5 and ASP.Net Creating HTML 5 Offline application

我没有遇到任何专门为asp.net构建的框架,例如可用于PHP或RoR的框架。以下是Steven的一篇很好的文章,旨在帮助您开始使用HTML 5和ASP.Net创建HTML 5脱机应用程序

#8


Obviously the offline version will not be able to talk to the server, but it does need to talk to something!

显然离线版本将无法与服务器通信,但它确实需要与某些东西交谈!

Enter HTML5 LocalStorage. It works like a database and enables you to put data on your client. Indeed you have to rework parts of your code in javascript and transmit it to the client, but then it would work offline.

输入HTML5 LocalStorage。它的工作方式类似于数据库,使您可以将数据放在客户端上。实际上,你必须在javascript中修改部分代码并将其传输到客户端,但随后它将脱机工作。

Local Storage works like this: - Setter: window.localStorage.setItem(KEY, VALUE) - Getter: window.localStorage.getItem(KEY) - Remove: window.localStorage.removeItem(KEY)

本地存储的工作方式如下: - Setter:window.localStorage.setItem(KEY,VALUE) - Getter:window.localStorage.getItem(KEY) - 删除:window.localStorage.removeItem(KEY)

To get the main page working offline you need to create a manifest. This is used to store complete sites on the client. Please refer to this for more information about manifests: http://diveintohtml5.info/offline.html

要使主页脱机工作,您需要创建清单。这用于在客户端上存储完整的站点。有关清单的更多信息,请参阅此处:http://diveintohtml5.info/offline.html

#9


You want to build a web application to work offline?? It can't be done.

您想构建一个Web应用程序以脱机工作?它无法完成。

You could split the interface code from the rest (in diferent dlls) and create a windows application to mimic the behaviour of your web application. This way you have 2 distinct user interfaces but the same code for business rules and data access.

您可以从其他(在不同的dll中)拆分接口代码,并创建一个Windows应用程序来模仿Web应用程序的行为。这样,您就拥有2个不同的用户界面,但业务规则和数据访问的代码相同。

I don't really see any other way...

我真的没有看到任何其他方式......

#1


There are plenty offline web apps nowaday. It simply evolve from AJAX.

现在有很多离线网络应用程序。它只是从AJAX演变而来。

For example:

WoaS (wiki on a stick / stickwiki), Tiddly Wiki,

WoaS(棍子上的维基/ stickwiki),Tiddly Wiki,

Google doc and Gmail is going to be offline.

Google文档和Gmail将脱机。

You don't need a webserver to run these webapps in offline mode. Just store the required data, scripts on the client side (usually as XML).

您不需要Web服务器即可在脱机模式下运行这些Web应用程序。只需在客户端存储所需的数据,脚本(通常为XML)。

#2


One of the possibilities would be to use Cassini. This is a web server that acts as a host for the ASP.Net runtime. You can host Cassini in a Windows application or a Windows Service. In this scenario you do not have to rewrite the web app and the web service.

其中一种可能性是使用卡西尼号。这是一个Web服务器,充当ASP.Net运行时的主机。您可以在Windows应用程序或Windows服务中托管Cassini。在这种情况下,您不必重写Web应用程序和Web服务。

Most other solutions do require a rewrite of both your web app and your web service. Depending on the way you have written the existing app you can reuse more or less code.

大多数其他解决方案都需要重写您的Web应用程序和Web服务。根据您编写现有应用程序的方式,您可以重复使用更多或更少的代码。

#3


Have you considered HTML5 with application cache and offline storage?

您是否考虑过具有应用程序缓存和离线存储的HTML5?

#4


If you hope to create an "offline" version of your package your biggest issue by far will be the need to install your site into a local copy of IIS (registering a virtual directory, etc.). I pursued this briefly a few years ago and gave up in frustration. It can be done: a number of software vendors such as DevExpress do this so you have local copies of their demonstration projects. Indeed, I was able to do this. The problem was the classic "it works on my computer" syndrome. There was simply no way to guarantee that most of my end-users had anywhere near the technical proficiency to make this work.

如果您希望创建程序包的“离线”版本,那么到目前为止最大的问题是需要将您的站点安装到IIS的本地副本(注册虚拟目录等)。几年前我曾短暂地追求这一点并且沮丧地放弃了。可以这样做:许多软件供应商(如DevExpress)都这样做,因此您可以获得其示范项目的本地副本。的确,我能够做到这一点。问题是经典的“它适用于我的电脑”综合症。根本没有办法保证我的大多数最终用户都具备接近技术熟练程度的能力。

Thus, I would strongly recommend that you not pursue this path unless you have very technically proficient users and a huge support staff.

因此,我强烈建议您不要追求这条道路,除非您拥有技术熟练的用户和庞大的支持人员。

But there is one more very important question: did you abstract all data access code to a DAL? If not, then you have a lot of work to do in managing data access as well.

但还有一个非常重要的问题:您是否将所有数据访问代码抽象为DAL?如果没有,那么您在管理数据访问方面还有很多工作要做。

Update: user "Rine" has recommended Cassini. I just wanted to let you know that I pursued Cassini and another 3rd-party web server as well. I think that there are licensing issues with Cassini but may be wrong - it has been awhile. However, I do distinctly remember running into barrier after barrier with this approach and very little documentation to help me out.

更新:用户“Rine”推荐了Cassini。我只是想让你知道我追求的是Cassini和另一个第三方网络服务器。我认为卡西尼存在许可问题,但可能是错误的 - 它已经有一段时间了。但是,我确实清楚地记得在使用这种方法进入障碍后进入屏障并且很少有文档来帮助我。

#5


if you want a web application run offline, you need a webserver (IIS for ASP) bound to the localhost (127.0.0.1) address. After this so can access your web application by typing http://127.0.0.1/ in your web browser the same way as you do online.

如果您希望Web应用程序脱机运行,则需要绑定到localhost(127.0.0.1)地址的Web服务器(IIS for ASP)。在此之后,可以通过在Web浏览器中键入http://127.0.0.1/来访问Web应用程序,方法与在线操作相同。

#6


If your AJAX relies on XMLHttpRequest's, you can:

如果您的AJAX依赖于XMLHttpRequest,您可以:

  1. Make the static versions of XML's you get over XMLHttpRequest and put then into a folder on disk.
  2. 创建XML的静态版本,然后将其放在XMLHttpRequest上,然后放入磁盘上的文件夹中。

  3. Rewrite your XMLHttpRequest URL's so that they point to files on disk.
  4. 重写您的XMLHttpRequest URL,以便它们指向磁盘上的文件。

  5. Rewrite your XMLHttpRequest's so that they don't check status (it's always 0 for the file:// protocol.
  6. 重写您的XMLHttpRequest,以便它们不检查状态(对于file://协议,它总是为0)。

All JScript works on file:// pages as well as on http:// ones.

所有JScript都可以在file:// pages以及http:// ones上运行。

Of course it's not the best way to develop static pages, but it may save you some time on rewriting.

当然,这不是开发静态页面的最佳方式,但它可以为您节省一些重写时间。

#7


I havent come across any framework specifically built for asp.net like the ones available for PHP or RoR. Here is a good article by Steven to get you started with HTML 5 and ASP.Net Creating HTML 5 Offline application

我没有遇到任何专门为asp.net构建的框架,例如可用于PHP或RoR的框架。以下是Steven的一篇很好的文章,旨在帮助您开始使用HTML 5和ASP.Net创建HTML 5脱机应用程序

#8


Obviously the offline version will not be able to talk to the server, but it does need to talk to something!

显然离线版本将无法与服务器通信,但它确实需要与某些东西交谈!

Enter HTML5 LocalStorage. It works like a database and enables you to put data on your client. Indeed you have to rework parts of your code in javascript and transmit it to the client, but then it would work offline.

输入HTML5 LocalStorage。它的工作方式类似于数据库,使您可以将数据放在客户端上。实际上,你必须在javascript中修改部分代码并将其传输到客户端,但随后它将脱机工作。

Local Storage works like this: - Setter: window.localStorage.setItem(KEY, VALUE) - Getter: window.localStorage.getItem(KEY) - Remove: window.localStorage.removeItem(KEY)

本地存储的工作方式如下: - Setter:window.localStorage.setItem(KEY,VALUE) - Getter:window.localStorage.getItem(KEY) - 删除:window.localStorage.removeItem(KEY)

To get the main page working offline you need to create a manifest. This is used to store complete sites on the client. Please refer to this for more information about manifests: http://diveintohtml5.info/offline.html

要使主页脱机工作,您需要创建清单。这用于在客户端上存储完整的站点。有关清单的更多信息,请参阅此处:http://diveintohtml5.info/offline.html

#9


You want to build a web application to work offline?? It can't be done.

您想构建一个Web应用程序以脱机工作?它无法完成。

You could split the interface code from the rest (in diferent dlls) and create a windows application to mimic the behaviour of your web application. This way you have 2 distinct user interfaces but the same code for business rules and data access.

您可以从其他(在不同的dll中)拆分接口代码,并创建一个Windows应用程序来模仿Web应用程序的行为。这样,您就拥有2个不同的用户界面,但业务规则和数据访问的代码相同。

I don't really see any other way...

我真的没有看到任何其他方式......