我如何获取服务器端的 HTML5 本地存储值

发布于 2024-12-16 13:31:10 字数 191 浏览 1 评论 0原文

我是一名.Net开发人员,我知道HTM5本地存储是客户端存储技术。我想获取服务器端本地存储的数据。

为了从服务器端获取 cookie 值,我们在 ASP.NET 中有 Request.Cookie。有没有类似的解决方案可以直接在服务器端获取本地存储值?请指导我。我正在使用 .net 4.0 框架

谢谢, 吉布

I am a .Net developer, I know that the HTM5 localstorage is client-side storage technique. I want to get the local storage data on the server-side.

For getting cookie value from server-side we have Request.Cookie in ASP.NET. Is there any solution like that to take the local storage value directly on the server-side? Please guide me. I am using the .net 4.0 framework

Thanks,
Jibu

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

囍孤女 2024-12-23 13:31:10

您需要使用标准 HTTP 技术将此信息从客户端传递到服务器。使用 javascript,您可以填写:

  • 隐藏字段
  • 查询字符串参数
  • POST
  • Ajax 调用服务器
  • ...

这完全取决于您的应用程序的组织方式、存储的信息类型、信息量、是否要重定向, ...但在所有情况下,这都应该使用 javascript 来完成,因为这是访问存储在 localStorage 中的数据的唯一方法。

You will need to pass this information from the client to the server using standard HTTP techniques. Using javascript you could fill:

  • Hidden fields
  • Query string parameters
  • POST
  • Ajax call to the server
  • ...

It will all depend on how your application is organized, what kind of information is being stored, its volume, whether you want to redirect or not, ... But in all cases this should be done using javascript since that's the only way to access data stored in localStorage.

陌伤ぢ 2024-12-23 13:31:10

不。本地存储的全部意义在于它是本地的。与 cookie 相比,它的优点之一是您可以在其中存储大量数据。 cookie 的优点之一是它们很小,因此将它们包含在对给定主机的每个 HTTP 请求中的开销很小。这两个优点是不兼容的,因此您不会希望将它们集成到单一技术中。

如果你想获取服务器上的数据,那么你需要让客户端显式地发送它(例如通过Ajax)。

No. The whole point of local storage is that it is local. One of the advantages of it over cookies is that you can store lots of data in it. One of the advantages of cookies is that they are tiny so the overhead of including them in every HTTP request to a given host is small. There two advantages are incompatible so you won't want them in a single technology.

If you want to get the data on the server, then you need to get the client to send it explicitly (e.g. via Ajax).

睡美人的小仙女 2024-12-23 13:31:10

这是一个广泛的问题。 (就像一段字符串的长度),但我会尝试让这变得有用:

  • 如果你在网络服务器的本地存储中有值,我假设你的网络服务器是JSON?或者你使用了sql本地存储选项吗?
  1. 无论存储类型如何,您都需要构建一个接口来处理:

a) 从本地数据库读取数据 ->如果您打算同步数据库,那么在这里涉及某种日期或索引值很重要...这是为了确保您按顺序发送数据库中的所有事务/更新。为此,您不仅必须将数据存储为包含信息的表,还必须将数据存储为包含更新发生时间和更新内容的事件的表。 (更改表)。这将有助于在服务器端检查一切是否同步,并且还意味着您不会将不需要且可以保存在本地的数据发送到服务器。 ((否则,如果您无法仅通过同步来节省服务器数据库空间,那么本地存储的意义何在?)

b)一个 HTTP 本地服务器,用于将数据发送到您的目标客户端服务器或数据库服务器等(但是您有设置您的基础设施) - 我建议您使用语言和服务器的行业标准,即 Ajax 和 JQuery。如果您进行大量数据流处理,那么我建议使用 Ajax 来研究 RXjs 来构建 http 接口(这个意义上的接口只是意味着像 API 一样公开客户端并发布 http 调用的一种方式)

c) 事件循环处理触发同步的频率和内容,这样您就不会过度破坏用户的计算机(您不想太频繁地执行此操作,但也希望它有意义,而不是“每天晚上”,也许用户在检测到同步时启用触发的事件wifi 再次可用。) - 我建议使用 Apache Cordova 内置的本机 wifi 读取功能以及服务器设置的行业标准(例如 Node.JS 的 Express.js)。

  1. 显然,后端服务器需要设置其 API 和身份验证/授权等。

This is a widescope question. (like the length of a piece of string), but Ill try to make this helpful:

  • If you have values in local store in webserver I assume your webserver is JSON? Or did you use the sql local storage option?
  1. Regardless of type of storage, you need to build an interface that both handles:

a) Reading data from your local database -> its important to involve some kind of date or index value in here if you are aiming to sync databases... this is to make sure you send IN ORDER all transactions / updates which are in your database. For this to happen you must store your data not only as tables with inforamtion but also tables that contain events of when updates happened and what was updated. (change tables). This will help check in the server end that everything is sync and also means you dont send data to the server that is not needed and can be kept locally. ((otherwise what is the point of local store if you cant save yourself server database space by only syncing waht is necessary?)

b) A HTTP local server to send the data to your destination client server or database server, etc (however you have set your infrastructure) - I recommend using industry standards for your language and server, which is Ajax and JQuery. If you do a lot of streaming of data then i recommend looking into RXjs with Ajax to get a http interface built (interface in this sense just means a way to expose your client like an API and post http calls)

c) An event loop to handle how often and what triggers the synchronization so that you dont destroy your users machine with overdoing it (you dont want to do this too often, but also want to it to be meaninful rather than "every night" maybe user enabled whenever you detect an event which triggers wifi available again.) - i recommend using native wifi reading capabilities built into Apache Cordova and also industry standards for your server setup (for example Express.js for Node.JS).

  1. Obviously the backend server needs to have its API set up and authentication / authorizations, etc.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文