javascript 如何在服务器端获取 HTML5 本地存储值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8134737/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 02:25:38  来源:igfitidea点击:

How can i get the HTML5 Local storage values in server side

javascripthtmlc#-4.0local-storage

提问by Jibu P C_Adoor

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.

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

For getting cookie value from server-side we have Request.Cookiein 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

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

Thanks, Jibu

谢谢,吉布

回答by Darin Dimitrov

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

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

  • Hidden fields
  • Query string parameters
  • POST
  • Ajax call to the server
  • ...
  • 隐藏字段
  • 查询字符串参数
  • 邮政
  • Ajax 调用服务器
  • ...

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.

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

回答by Quentin

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.

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

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).

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