MVC 3 显示用户特定数据

发布于 2024-12-01 19:10:05 字数 157 浏览 9 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

老子叫无熙 2024-12-08 19:10:05

在您自己的数据模型中拥有一个使用主键 UserName 的表。该值将决定向用户显示哪堵墙。

当用户注册时,在使用 ASP.NET 会员资格提供程序创建用户后,向 Users 表添加一个新行,提供与会员资格提供程序中的用户名相同的用户名(为简单起见,我们使用电子邮件地址作为用户名 - 更容易保证唯一性)。您可以使用 Controller 类的 User 属性对其墙数据执行查询。

  1. 用户注册,您为他们创建一个用户帐户 (Membership.CreateUser)
  2. 在 Membership.CreateUser 的同时,将 UserName 插入到数据模型上的一行
  3. 中 用户登录
  4. 用户请求页面
  5. 页面使用 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.

  1. User registers, you create a user account for them (Membership.CreateUser)
  2. At same time as Membership.CreateUser, insert UserName into a row on your data model
  3. User signs in
  4. User requests page
  5. Page uses the Controller.User property to query your app database for the correct wall content to display.
掩饰不了的爱 2024-12-08 19:10:05

我建议在 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文