MVC 3 显示用户特定数据
我正在尝试使用 MVC 3 创建一个网站应用程序 - 问题是我想设置一个网站,用户登录后只能看到特定于他们的数据。例如,当您登录 Facebook 时,您只能看到自己的“墙”,而看不到其他人。
有人可以向我指出如何设置可以将数据连接到用户的数据库的教程吗?
提前致谢!
I am trying to create a web site app using MVC 3- The problem is I want to setup a website where a user signs in they see data only specific to them. For example when you log into facebook, you only see your "wall" and not other peoples.
Can someone point me to a tutorial on how to setup a database where data can be connected to a user?
thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您自己的数据模型中拥有一个使用主键 UserName 的表。该值将决定向用户显示哪堵墙。
当用户注册时,在使用 ASP.NET 会员资格提供程序创建用户后,向 Users 表添加一个新行,提供与会员资格提供程序中的用户名相同的用户名(为简单起见,我们使用电子邮件地址作为用户名 - 更容易保证唯一性)。您可以使用 Controller 类的 User 属性对其墙数据执行查询。
Have a table in your own data model that uses a primary key UserName. This is the value that will determine which wall you show to the user.
When a user registers, after you create them using the ASP.NET Membership Provider, add a new row to the Users table giving the same UserName as the UserName in the membership provider (for simplicity, we use email address for username -- easier to guarantee uniqueness). You can execute queries for their wall data by using the User property of the Controller class.
我建议在 asp.net/mvc 上阅读一些教程。我不确定 Nerddinner 是否已针对 MVC3 进行了更新(顺便说一句,这是一个很棒的教程,由 Scott Guthrie 编写),但看起来以下教程具有登录功能,并在基本级别解释了如何处理用户特定数据:
< a href="http://www.asp.net/mvc/tutorials/getting-started-with-mvc3-part1-cs" rel="nofollow">MVC3 教程
I would suggest some of the tutorials over at asp.net/mvc. I am not sure if Nerd Dinner has been updated for MVC3 (a great tutorial by the way, written by Scott Guthrie), but it looks like the following tutorial has login functionality and explains at a basic level how to handle user specific data:
MVC3 Tutorial