如何跨没有应用程序变量和数据库的多个用户共享数据? [英] How to share data across multiple users without application variable and database ?

查看:80
本文介绍了如何跨没有应用程序变量和数据库的多个用户共享数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





在一次采访中,我被问到一个关于ASP.NET的问题,我们如何在不使用应用程序变量和数据库逻辑的情况下在多个用户之间共享数据?



谢谢

Hi,

In an interview I was asked a question about ASP.NET that how can we share data among multiple users without using application variable and database logic?

Thanks

推荐答案

有很多选项,有些是在实际的Web开发框架中定义的(HTML和JavaScript API),有些是ASP.NET的API。由于他对应用程序变量不感兴趣,这意味着他有兴趣向您询问客户端API,共享数据的JavaScript方式或共享数据的HTML方式。



在HTML中,您可以使用表单的action属性将数据从一个页面发送到另一个页面。您可以在action属性中指定第二页的URL,然后将其发送到下一页。然后,可以在该页面上轻松访问表单中的数据。例如,以下HTML标记,



There are quite a multiple options, some are defined in the actual web development framework (HTML and JavaScript APIs) and some are ASP.NET's APIs. Since he was not interested in the Application variables, it means that he was interested in asking you about the client-side APIs, JavaScript way of sharing the data or HTML way of sharing the data.

In HTML, you can send the data from one page to another page, using the action attribute of the form. You can assign the URL of the second page in the action attribute and then you can send it to the next page. The data in the form, can be then easily accessible on that page too. For example, the following HTML markup,

<form method="post" action="~/second_page.html">
   <!-- Empty form -->
</form>





该表格一旦提交,将被重定向到 second_page.html ,您可以使用此页面中填写的数据。您将被要求使用一些服务器端语言; ASP.NET或其他一些因此确保您使用正确的文件格式。



另一种做同样事情的方法是使用JavaScript的API。 localStorage,sessionStorage有两种方法可以存储来自一个页面的数据,然后在不同的页面上(在同一个应用程序中)使用它。您可以通过来自MDN的存储API 了解更多信息[ ^ ]。您可以存储任何类型的数据,然后在其他页面上提取值。



例如,这是来自MDN的此方案的示例代码。





That form, upon submission, would be redirected to the second_page.html and there you can use the data filled in this page. You would be required to use some server side language; ASP.NET or some other so make sure you're using correct file format.

Another way of doing the same thing is using the JavaScript's APIs. localStorage, sessionStorage are two ways that you can store the data from one page, and then use it on different pages (across the same application). You can learn more on Storage APIs from MDN[^]. You can store any type of data, and then extract the value on other pages.

For example, this is an example code for this scenario from MDN.

// Save data to the current session's store
sessionStorage.setItem("username", "John");

// Access some stored data
alert( "username = " + sessionStorage.getItem("username"));





无论如何,我写了一篇文章说可以让您了解可用于在网站上的多个网页上共享数据的过程和方法。您可以在此处阅读该文章:如何在使用ASP.NET的不同网页 [ ^ ]。记住,我也在那里提到过,我也会在这里说。不要在客户端API中存储密码等敏感数据。用户可以轻松操纵它们。始终将这些值存储在服务器端;应用程序变量或更好的数据库。



Anyhow, I have written an article that would let you understand the processes and methods that you can use to share the data across multiple web pages on your website. You can read that article here: How to share data among different web pages using ASP.NET[^]. Remember, I have also mentioned there, and I will say it here too. Do not store sensitive data such as password in client-side APIs. User can easily manipulate them. Always store such values on the server-side; Application variables or more better in a database.


这篇关于如何跨没有应用程序变量和数据库的多个用户共享数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆