.net MVC 用户/组身份验证
我正在学习 .net mvc3,我对用户身份验证的工作原理感到非常困惑,希望你们能给我指出正确的方向。我的应用程序需要拥有用户和组,每个用户和组都需要存储超出身份验证所需的数据。例如,我的用户对象需要能够存储电话、传真和电子邮件数据以及他们是否是项目经理。我的小组需要存储有关该小组的一些其他数据,例如网站。
我正在将 Entity 用于我的其他模型。
我应该为我的用户和组创建模型并以某种方式将它们与成员身份验证链接起来吗?或者这种东西是以某种方式内置的?或者我需要一个定制的会员提供商吗?
抱歉,如果我看起来很无知。我只做了一周的.net。
如果这有助于解释的话,我有 Django 背景。
谢谢!!
I am learning .net mvc3 and I am very confused about how user authentication works and was hoping y'all could get me pointed in the correct direction. My application needs to have users and groups, each of with needs to store data beyond what is needed for just authentication. For example, my user object needs to be able to store phone, fax, and email data and whether they are the project manager or not. My group needs to store some other data about that group such as website.
I am using Entity for my other models.
Should I create models for my user and group and somehow link them with the membership authentication? Or is the type of thing built in somehow? Or do I need a custom membership provider?
Sorry if I seem ignorant. I have only been doing .net for a week.
I come from a Django background if that helps in the explanation.
Thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您当然可以使用表单身份验证并利用默认的 aspnet_Users 和 aspnet_Roles 表来处理登录帐户和站点可能拥有的各种角色等事务,然后将角色分配给用户。这将允许您
[Authorize(Roles = "Administrators")]
您的控制器操作来控制谁可以做什么。如果基于该指定控制数据库有意义,您可以在此级别设置“项目经理”角色并分配该角色。如果没有,您可以将该信息放入您自己的表中。就我而言,我需要将数据与用户关联,因此我在自己的数据库中创建了一个特定于应用程序的用户表,然后通过向我自己的用户表添加 Guid 列,将用户的 aspnetdb 用户表行链接到应用程序的用户表并使用 aspnet_Users 表数据中的 UserId 填充该值。这样,当用户登录系统时,我可以检索适当的数据(例如“我的食谱”)。可能有不同/更好的方法来解决这个问题,但这就是我最终针对自己的情况所做的。在我的应用程序的数据库中,我刚刚创建了自己的表来处理用户和组等内容,因为有很多感兴趣的字段。我根本不想更改 aspnetdb 中的表。不过,我很想听听其他人的想法。
您可以在此处查看我发布的有关此主题的问题。
You can certainly use forms authentication and utilize the default aspnet_Users and aspnet_Roles tables to handle things like login accounts and the various roles that you might have for the site, and then assign the roles to the users. That'll allow you to
[Authorize(Roles = "Administrators")]
your controller actions to control who can do what. You could set up a "Project Manager" role at this level and assign that, if it makes sense to control the DB based on that designation. If not, you could put that information in your own table.In my case I needed to associate data with users and so I created an application-specific Users table in my own database and then linked the aspnetdb Users table row for a user to the application's Users table by adding a Guid column to my own Users table and populated that with the UserId from the aspnet_Users table data. That way when the a user logged into the system, I could retrieve the appropriate data (e.g., "My recipes"). There may be different/better ways to solve this problem, but that's what I ended up doing for my own situation. In my application's db, I just created my own tables to handle things like your Users and Groups since there were quite a few fields of interest. I didn't want to alter the tables in the aspnetdb at all. I'll be interested, however, to hear what other folks think.
You can see a question I posted about this subject here.