与用户相关联的数据 [英] Associating data with a user

查看:120
本文介绍了与用户相关联的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关我的第一个ASP.NET MVC 3应用程序中,我使用了 aspnet_Users aspnet_Roles 表提供验证我的用户和少数几个角色。这似乎工作pretty好。此外,我想在各种表的登录用户和行之间的关联。

For my first ASP.NET MVC 3 application, I'm using the aspnet_Users and aspnet_Roles tables to provide authentication for my users and for a few roles. That seems to work pretty well. Additionally, I want to make associations between the logged-in user and rows in various tables.

作为一个具体的例子,我有它有特定的食谱列的食谱表(姓名,日期,属性)以及一个用户名列。这用户名列是目前的外键一个用户表在我IceCreamDB(不是在ASPNETDB aspnet_Users 表),其中包含有关该系统的用户的各种特定领域的信息。因此,它很容易创建检索所有马特的食谱查询,通过建立在我的名为马特的用户表中的用户谁拥有某个整数用户ID,然后使用该用户ID在创建和更新到食谱表。太好了。

As a concrete example, I've got a Recipes table which has columns specific to recipes (name, dates, attributes) as well as a UserID column. That UserID column is currently a foreign key to a Users table in my IceCreamDB (NOT the aspnet_Users table in the aspnetdb) which contains various domain-specific information about users of the system. So, it's easy enough to create a query that retrieves all of Matt's recipes, by creating a user in my Users table named Matt who has some integer UserId and then use that UserId during Creates and Updates to the Recipes table. Great.

要扎登录的用户itsmatt(从aspnet_Users表格内),以马特我IceCreamDB的用户表用户ID,我在它与aspnet_Users ID(它的一个GUID)填写IceCreamDB用户表中的GUID列为登录。

To tie the logged-in user "itsmatt" (from the aspnet_Users table) to my IceCreamDB's Users table UserId for Matt, I have a Guid column in IceCreamDB Users table which is filled in with the aspnet_Users Id (its a Guid) for the login.

IceCreamDB的用户表:

IceCreamDB's Users table:

 UserId     1               // primary key used as FK for other tables 
 UserName   Matt
 Phone      555-1212
 Department Product Development
 Building   2-A
 Office     221
 UserGuid   7fc75a6c-7e32-43f3-be8c-be0122bf54cb // Guid from aspnetdb User table

和这个工程确定 - 作为用户注册过程的一部分,我创建了一个aspnet_User,设置任何角色(例如,管理员,业主,生产)是合适的,然后创建一个用户条目在IceCreamDB用户表,复制的Guid到新行。这让我登录到该网站,看到我的食谱或我的命令。

And this works OK - as part of the user registration process, I create an aspnet_User, set up whatever roles (e.g., "Administrators", "Owners", "Production") are appropriate, and then create a user entry in the IceCreamDB Users table, copying the Guid into the new row. This lets me log into the website and see my recipes or my orders.

不过,我觉得我已经自酿这种解决方案,并可能有更好的,不同的方式来这样做。我想在此方面的指导。

But I feel I've home-brewed this solution and there's likely a better, different approach to doing this. I'd like some guidance on this.

推荐答案

据我知,这是一个相当普遍的解决方案。其他2我知道正在使用的 aspnet_Profile 为简单的设置,或者编辑 aspnet_Users 表,这是不一个好的解决方案,因为如果你有更多的应用程序( aspnet_Applications )使用相同的 aspnet_Users 最终不得不领域该表上的哪一个应用程序可能使用(不可为空),另一个没有。

As far as I known, this is a quite common solution. The 2 other I'm aware of are using aspnet_Profile for simple settings, or editing the aspnet_Users table, which is not a good solution, because if you'd have more applications (aspnet_Applications) using the same aspnet_Users your end up having fields on that table which one application might use (not nullable) and the other doesn't.

本教程他们基本上做同样的事情。

In this tutorial they are basically doing the same thing.

这篇关于与用户相关联的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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