采用“aspnet_...” ASP.NET MVC 中的 SQL 表

发布于 2024-08-22 17:50:51 字数 516 浏览 3 评论 0原文

我刚刚在 ASP.NET MVC 上启动一个新项目,这将是第一个实际使用该技术的项目。当我使用 Visual Studio 2010 创建新项目时,它在我的 sql 服务器中创建了一堆带有“aspnet_”前缀的表。其中一部分涉及内置用户帐户和权限支持。

现在,我想保留有关我的用户的一些特定信息。我的问题是“更改此 aspnet_ 表的结构以满足我对用户帐户信息的需求是一个好习惯吗?”。

我想答案是“不”。 (到底为什么?),我打算创建自己的“用户”表。连接 aspnet_Users 表和我自己的自定义用户表中的记录的好方法是什么。

我希望关系是 1:1,并且数据库中的设计在我的 C# 代码中尽可能透明(如果很重要,我会使用 linq to sql)。另外,我不想将用户名和密码从 aspnet_ 表复制到我的表并维护数据。

我正在考虑使用视图来加入他们。这是个好主意吗?

提前致谢!

编辑:从答案中,我发现我可能不够清楚我想要什么。问题不在于是否使用默认的 asp.net 提供程序,而是如何根据我的需要采用它。

I'm just starting a new project on ASP.NET MVC and this will be the first project actually using this technology. As I created my new project with Visual Studio 2010, it created to my sql server a bunch of tables with "aspnet_" prefix. Part of them deal with the built-in user accounts and permission support.

Now, I want to keep some specific information about my users. My question is "Is it a good practice changing the structure of this aspnet_ tables, to meet my needs about user account's information?".

And as i suppose the answer is "No." (Why exactly?), I intend to create my own "Users" table. What is a good approach to connect the records from aspnet_Users table and my own custom Users table.

I want the relationship to be 1:1 and the design in the database to be as transparent as possible in my c# code (I'm using linq to sql if it is important). Also, I don't want to replicate the usernames and passwords from the aspnet_ tables to my table and maintain the data.

I'm considering using a view to join them. Is this a good idea?

Thanks in advance!

EDIT: From the answer, I see that I may not be clear enough, what I want. The question is not IF to use the default asp.net provider, but how to adopt it, to my needs.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

呆橘 2024-08-29 17:50:51

我将创建 自定义会员提供程序 并省略那些 aspnet_x 表完全地。我已经看到当一个人使用 nhibernate 映射加入这些表和自定义表时会发生什么 - 纯粹是噩梦。

I would create custom membership provider and omit those aspnet_x tables completely. I've seen what happens when one joins these tables and custom ones with nhibernate mappings - pure nightmare.

不必在意 2024-08-29 17:50:51

如果您选择为您的网站使用会员 API,则此 链接包含有关如何向用户添加额外信息的信息。

我最近遇到了同样的情况,最终放弃了会员功能,并与 DotNetOpenAuth 库一起推出了我自己的数据库解决方案。

If you are choosing to use the Membership API for your site, then this link has information regarding how to add extra information to a user.

I was faced with the same scenario recently and ended up ditching the membership functionality and rolled my own db solution in tandem with the DotNetOpenAuth library.

哭泣的笑容 2024-08-29 17:50:51

在 asp.net 中使用会员系统有其优点和缺点。它很容易启动,因为您不必担心验证、用户注册、重置密码。 (如果您打算修改表结构,请小心,您必须在生成的视图/存储过程中更改它们

但是使用会员资格也有缺点
您将必须维护两个独立的系统,因为会员 API 有限制,例如,您无法使用会员 API 在事务内执行操作。 (我认为除非你使用 TransactionScope,但你没有其他选择)。

一个有效的替代方案是实现您自己的安全验证例程并使用 FormsAuthentication。这样您就可以完全控制您的用户表,并消除对会员资格 API 的依赖。

Using the membership system in asp.net has its advantages and drawbacks. It's easy to start, because you don't have to worry about validation, user registration, resetting passwords. (Be careful if you plan to modify the table structures, you will have to change them in the views/store procedures generated

However there are drawbacks to using Membership
You will have to maintain 2 separated systems, because the Membership API has restrictions, for example, you cannot perform operations inside a transaction with the membership api. (Unless you use TransactionScope i think, but you don't have other choices).

A valid alternative would be to implement your own security validation routines, and using FormsAuthentication. This way you will have total control over your users tables, and remove dependency to the membership API.

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