我怎么能隔离用户“在ASP.net MVC应用程序中的数据? [英] How can I isolate users' data in ASP.net MVC application?

查看:103
本文介绍了我怎么能隔离用户“在ASP.net MVC应用程序中的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个asp.net应用程序(使用MVC5,ASP 4.5,EF)部署在Azure上。该应用程序允许用户注册和登录。
然而,一旦登录,任何人都可以看到其他人的数据。

So I have an asp.net application (using MVC5, ASP 4.5, EF) deployed on Azure. The application allows users to register and login. However, once logged in, anyone can see everyone else's data.

什么是数据隔离属于不同的用户,使每个用户只能看到他/她创建数据的最佳实践?

What is the best practice to isolate the data belonging to different users so that each user can only see the data he/she creates?

另一个小问题是如何Facebook的分离其用户的数据?

Another small question is how does Facebook separates its users' data?

感谢

推荐答案

有关的每一块数据的用户创建,储存他们的用户ID,只允许用户看到了他们的用户ID数据。一对夫妇的例子:

For every piece of data a user creates, store their user ID and only allow users to see data that has their user ID. A couple of examples:

SQL:

SELECT UserDataID, Value FROM UserData WHERE UserID = @UserID;

在传递用户的ID到 @UserID 参数。

LINQ:

using (var entityFrameworkContext = new MyDataEntities())
{
    var currentUserData = entityFrameworkContext.UserData.Where(userData -> userData.UserID = currentUserID);
}

其中, currentUserID 可能是从窗体身份验证的用户名或ID,例如: HttpContext.Current.User.Identity.Name

Where currentUserID could be the user name or ID from forms authentication, for example: HttpContext.Current.User.Identity.Name.

这篇关于我怎么能隔离用户“在ASP.net MVC应用程序中的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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