我应该如何在ASP.NET中声明一个数据表以避免与其他用户共享数据? [英] How should I declare a datatable in ASP.NET to avoind shared data with other users?

查看:100
本文介绍了我应该如何在ASP.NET中声明一个数据表以避免与其他用户共享数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。

我是ASP.Net和这个网站的新手所以请原谅明显的错误。



我有一个VB。 Net Winforms应用程序,我将其更改为ASP.Net应用程序的基础知识。

在Winforms版本中,我有一个数据表,其数据特定于用户并且我声明为公共共享。我在ASP.Net版本中做了同样的事情,但很快就知道这是错误的,因为数据是在用户之间共享的。



我怀疑我应该将数据表声明为会话变量,以确保该表的数据特定于该用户。然而,在搜索了各种来源之后,我能找到的唯一建议是将数据表声明为公共而不是公共共享,这就足够了。



然而,这样做我发现刷新页面时数据表不存在。请有人可以告知这里的正确流程。



我应该将数据表声明为会话变量,还是应该在每次刷新页面时声明并刷新数据。



任何建议都将不胜感激。



非常感谢



我尝试过:



我搜索了各种资源,包括这个网站。无法清楚地理解问题

Hi everyone
I am new to ASP.Net and this site so please forgive obvious blunders.

I had a VB.Net Winforms app, the basics of which I changed to an ASP.Net app.
In the Winforms version I had a datatable, the data of which was specific to a user and that I declared as Public Shared. I did the same in the ASP.Net version but soon learned that this was wrong as the data was being shared between users.

I suspected that I was supposed to declare the datatable as a session variable in order to make sure that the data for that table was specific to that user. However, after searching various sources, the only suggestion I could find was to declare the datatable as Public and not Public Shared and this would suffice.

However, on doing this I find that the datatable does not exist when the page is refreshed. Please can someone advise what the correct process is here.

Should I be declaring the datatable as a session variable, or should I be declaring it and refreshing the data on every page refresh.

Any advice would be appreciated.

Many thanks

What I have tried:

I have searched various resources, including this site. Unable to get a clear understanding f the issue

推荐答案

最简单的答案是你应该将它存储在会话中



The simplest answer is that you should store it in the session

Session("MyData") = myDataTable





最好的答案可能比那更复杂。您需要尝试停止像桌面应用程序一样思考,网站不是桌面应用程序。在一个网站没有持久性,服务器不知道你是谁在请求之间,所以像Session这样的东西提供持久存储,但如果你有10,000个用户,你的数据表大小是1Mb那么那就是很多服务器内存中的数据。在桌面应用程序上无关紧要,因为每个用户都将数据存储在自己的本地内存中,但在Web应用程序中,所有数据都存储在服务器上。



因此,根据用户数量,数据大小以及检索数据的速度,您可能根本不想将其存储在会话中,而是每次都检索它。



The best answer is probably more complicated than that. You need to try and stop thinking like a desktop app, a website is not a desktop app. In a website there is no persistence, the server doesn't know who you are between requests so things like the Session are there to provide that persistent store, but if you have 10,000 users and your datatable is 1Mb in size then that's a lot of data in the server's memory. It doesn't matter on a desktop app as each user stores that data in their own local memory, but in a web app all that data is stored on the server.

So depending on the number of users, the size of the data and how quickly you can retrieve the data you might want to not store it in the session at all but retrieve it every time.


这篇关于我应该如何在ASP.NET中声明一个数据表以避免与其他用户共享数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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