ASP MVC 用户配置文件
我以前做过MVC,但我对ASP 和ASP MVC 很陌生。到目前为止,我真的很喜欢 ASP MVC 为我提供的便利,但我无法弄清楚如何更好地控制用户。默认情况下,MVC 提供最小的用户注册表单。我环顾四周,但仍然有两个问题:
如何使用户数据库成为我的项目中的本地数据库?我认为 SQLEXPRESS 用于存储用户值,这似乎是一个神奇的过程。我该如何消除这种魔力?我想对该数据库的位置有更多的控制。
这引出了另一个问题:如何扩展用户?我一直在阅读个人资料,但我仍然对一些事情感到困惑。如何准备个人资料并将其与用户链接?什么作为外键?而且,在我的控制器中,我如何访问用户的各个部分,例如用户名、电子邮件,甚至从个人资料中访问名字、姓氏(尽管我猜想,当我在本地拥有个人资料数据库和用户数据库时,我可以运行sql 命令来检索数据)
我真的很感激一些指向正确资源的指针,和/或 ASP.NET 的最佳实践
I've done MVC in the past, but I am new to ASP and ASP MVC. I really love the ease that ASP MVC provides me, so far, but I am having trouble figuring out how to get more control over the Users. By default, the MVC provides a minimal user registration form. I have looked around quite a bit, but I still have two questions:
How do I make the User data base a local database in my project? I think SQLEXPRESS is used to store the user values, in what seems like a magical process. How do I de-magic-ify this? I would like to have more control on the location of this database.
This leads to another question: How do I expand the User? I have been reading up on Profiles, but I am still confused about a few things. How do I prepare a Profile and link it with a User? What serves as the foreign key? And, in my controllers, how can I access various parts of the user like username, email, or even from the profile stuff like firstname, lastname (though I guess once when I have a Profile's database and a User's database locally, I can run sql commands to retrieve data)
I would really appreciate some pointers to the right resources, and/or best practices with ASP.NET
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我首先阅读这篇关于扩展的官方 Microsoft 文章 ASP.NET 会员 API。它讨论了创建额外的表来存储有关用户的附加信息。
会员数据库
创建附加表
这部分实际上非常简单,由几个简短的步骤组成:
uniqueidentifier
列作为主键,并添加一个aspnet_Users 表的外键这是一个关于使用的小示例
将此代码段添加到负责配置文件/帐户信息的存储库中。
然后在模型中,您可以获取用户并访问其他用户存储在 UserProfiles 表中的信息。
差不多就是这样!
这显然是一个简单的示例,您应该检查用户是否为 null > 您还可以创建一个类,负责返回有关用户的必要信息、实现缓存等。
I would start by reading this official Microsoft article on extending the ASP.NET Membership API. It talks about creating extra tables for storing additional information about users.
The membership database
Creating additional tables
This part is actually quite simple and consists of a few short steps:
uniqueidentifier
column as your primary key, and add a foreign key to the aspnet_Users tableHere's a little sample on usage
Add this snippet to your repository responsible for Profile/Account information.
Then inside your models, you can get the user and access the other information stored in your UserProfiles table.
And that's pretty much it!
This is obviously a simple example, and you should be checking if the user is null and you could also create a class responsible for returning the necessary information about a user, implement caching, etc..
我将从这里开始:
另外还有一个很棒的文章系列(18 篇文章!!!)来自 Scott米切尔 4GuysFromRolla 。
ASP.NET 成员资格模型被设计为具有可插入的体系结构。您可以编写自己的最适合您需求的 MembershipProvider 实现。
即使您在网上找到的大多数示例都涉及 ASP.NET Web 表单,但与 MVC 一起使用时也只有非常小的差异。
I would start from here:
Also a great article series (18 articles!!!) is from Scott Mitchell at 4GuysFromRolla.
The ASP.NET membership model is desgned to have a pluggable architecture. You can write you own MembershipProvider implementation that best suit your needs.
Even if most of the samples you will find on the net regards ASP.NET web forms, there are only very small differences when used with MVC.
如果您仍在寻求对此的深入了解,我刚刚发现在 MVC 4 WebPages 站点中,有一个名为 SimpleMembership 提供程序的提供程序。它为开发人员提供了对网站上存储的用户、角色和会员信息的更多控制。更多这里:
http://blog.osbornm .com/archive/2010/07/21/using-simplemembership-with-asp.net-webpages.aspx
If you're still looking for insight into this, I just ran across the fact that in MVC 4 WebPages sites, there's a provider called the SimpleMembership provider. It gives more control to the developer of the Users, Roles and Membership info stored on websites. More here:
http://blog.osbornm.com/archive/2010/07/21/using-simplemembership-with-asp.net-webpages.aspx