使用ASP.NET SQL成员资格提供程序,如何存放我自己的每个用户的数据? [英] Using ASP.NET SQL Membership Provider, how do I store my own per-user data?

查看:98
本文介绍了使用ASP.NET SQL成员资格提供程序,如何存放我自己的每个用户的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ASP.NET SQL成员资格提供程序。因此,有有我的每个用户的细节的 aspnet_Users 表。 (实际上, aspnet_Membership 表似乎包含大部分的实际数据)。

I'm using the ASP.NET SQL Membership Provider. So, there's an aspnet_Users table that has details of each of my users. (Actually, the aspnet_Membership table seems to contain most of the actual data).

我现在要存储在我的数据库某些每个用户的信息,所以我想我只是创建一个新表使用用户ID (GUID)列和FK关系 aspnet_Users 。但是,我这时才发现,我不能轻易得到访问用户ID 因为它不是通过会员的API暴露。 (我知道我可以通过访问它的 ProviderUserKey ,但它似乎是API被抽象掉内部的用户名中推荐使用用户名,我不想走得太远对粮食)。

I now want to store some per-user information in my database, so I thought I'd just create a new table with a UserId (GUID) column and an FK relationship to aspnet_Users. However, I then discovered that I can't easily get access to the UserId since it's not exposed via the membership API. (I know I can access it via the ProviderUserKey, but it seems like the API is abstracting away the internal UserID in favor of the UserName, and I don't want to go too far against the grain).

所以,我想我应该不是把 LoweredUserName 列在我的表,并创建 aspnet_Users的FK关系这一点。 Bzzzt。又错了,因为虽然没有在 aspnet_Users 的唯一索引包括的的 LoweredUserName ,它还包括的applicationID - 所以为了创建我的FK的关系,我需要有一个的applicationID 列在我的表了。

So, I thought I should instead put a LoweredUserName column in my table, and create an FK relationship to aspnet_Users using that. Bzzzt. Wrong again, because while there is a unique index in aspnet_Users that includes the LoweredUserName, it also includes the ApplicationId - so in order to create my FK relationship, I'd need to have an ApplicationId column in my table too.

起初我以为:很好,我现在只处理一个单一的应用程序,所以我就添加这样一列,并给它一个默认值。然后,我意识到的applicationID 是一个GUID,所以它会是一个痛苦的做到这一点。不是的硬盘的准确,但直到我推出我的数据库,我不能predict什么GUID将是

At first I thought: fine, I'm only dealing with a single application, so I'll just add such a column and give it a default value. Then I realised that the ApplicationId is a GUID, so it'd be a pain to do this. Not hard exactly, but until I roll out my DB I can't predict what the GUID is going to be.

我觉得我失去了一些东西,或者去的事情走错了路。什么是我的应该的怎么办?

I feel like I'm missing something, or going about things the wrong way. What am I supposed to do?

推荐答案

我认为你正在寻找ProfileProvider这让你想要与用户的任意信息关联起来。

I think you are looking for the ProfileProvider which let's you associate any arbitrary information you wish with the user.

ASP.NET配置文件属性概述

加成如果内置ProfileProvider不会满足您的需求,那么你可以考虑通过编写从 System.Web.Profile派生的类实现自己的ProfileProvider。 ProfileProvider 。这将使你写的东西,避免在您的评论中提到的序列化问题。

ADDITION If the built-in ProfileProvider will not suit your needs, then you might consider implementing your own ProfileProvider by writing a class that derives from System.Web.Profile.ProfileProvider. This would enable you to write something that avoids the serialization issues you mentioned in your comment.

实现配置文件提供商

加成注意有关SqlMembershipProvider的。你确实是正确的,因为成员类真的键入用户名上即使架构是在用户ID关键字。这简直是​​一场有关SqlMembershipProvider的班我的眼中钉之一。这实际上在你想要一个用户存储,但独立的应用程序列表中的角色多应用环境造成的问题。

ADDITION Note about the SqlMembershipProvider. You are indeed correct that the Membership classes are really keyed on username even though the schema is keyed on UserId. This is frankly one of my pet peeves about the SqlMembershipProvider classes. This actually creates problem in a multi-application environment where you want a single user store but independent application role lists.

我的建议是对用户ID键入,因为它是,正如你所说,aspnet_Users表格内的主键和所有的外键关系被使用,它是一个单一的值。如果您在LowerUsername(和的applicationID),以及用户名更改键,您就需要启用级联更新,使这一变化涟漪您的自定义表。

My recommendation would be to key on UserId since it is, as you mentioned, the primary key of the aspnet_Users table and is used in all the foreign key relationships and it is a single value. If you key on LowerUsername (and ApplicationId), and the username changes, you'll need to have cascade update enabled so that the change ripples to your custom tables.

这篇关于使用ASP.NET SQL成员资格提供程序,如何存放我自己的每个用户的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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