SimpleMembership 与 ASP.NET MVC 4 中的自定义数据库架构 [英] SimpleMembership with custom database schema in ASP.NET MVC 4

查看:25
本文介绍了SimpleMembership 与 ASP.NET MVC 4 中的自定义数据库架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想启用 ASP.NET MVC 4 的 SimpleMembership API 以与我自己的数据库架构集成.我的数据库中有一个简单明了的表,名为 Users,其中包含以下字段:

I want to enable the ASP.NET MVC 4's SimpleMembership API to integrate with my own database schema. I have a plain and simple table in my database called Users with these fields:

  • ID
  • 姓名
  • 密码
  • 电子邮件
  • IsDeleted

我已经配置了 SimpleMembership API 以使用我的数据库:

I have already configured the SimpleMembership API to use my database:

WebSecurity.InitializeDatabaseConnection("MyStuff", "Users", "Id", "Name", autoCreateTables: true);

我也可以插入一个用户:

And I can insert a user too:

WebSecurity.CreateUserAndAccount(model.UserName, model.Password, 
                                 new 
                                 { 
                                        IsDeleted = false, 
                                        Email = "sampledata@gmail.com"                
                                 });

然而,Password 字段(或它的哈希值)没有插入到 Users 表中(当然),它插入到另一个名为 webpages_Membership 的表中,该表由 InitializeDatabaseConnection 创建代码>调用并包含很多我不需要的不必要的信息.

However, the Password field (or it's hash) is not inserted into the Users table (of course), it inserted into another table called webpages_Membership which is created with the InitializeDatabaseConnection call and contains a lot of unnecessary information which I don't need.

此外,我还有其他自动创建的表,称为 pages_OAuthMembership、webpages_Roles 和 pages_UsersInRoles,我不需要这些表.

Also, I have other automatically created tables called webpages_OAuthMembership, webpages_Roles and webpages_UsersInRoles which I don't need.

我已经尝试将表生成设置为 false:

I've already tried to set the table generation to false:

WebSecurity.InitializeDatabaseConnection("MyStuff", "Users", "Id", "Name", autoCreateTables: false);

但在这种情况下,CreateUserAndAccount 调用将抛出异常,因为它找不到 pages_Membership 表.

But in this case the CreateUserAndAccount call will throw an exception because it will not find the webpages_Membership table.

当我想使用 SimpleMembership API 时,看起来需要这些表.

It looks like these tables needed when I want to use the SimpleMembership API.

我的问题是:当我只想要一个简单的 Users 表而仅此而已时,在这种情况下我应该怎么做?

My question is that: what should I do in a scenario like this when I want only a simple Users table and nothing more?

我是否必须自己编写整个会员处理和身份验证逻辑(哈希代码生成等)?

Do I have to write the whole membership handling and the authentication logic (hash code generation, etc.) myself?

推荐答案

我向产品团队提出了同样的问题.

I asked the same question to the product team.

SIMPLE 会员资格的设计目标是尽可能简单地开箱即用.

The design goal of SIMPLE membership was to work out-of-the box as simple as possible.

因此,就表格而言,确实无法进行自定义.推荐的解决方法是,仍然使用 ASP.NET Membership (SqlMembershipProvider).

So really there's no customization possible as far as the tables are concerned. The recommended workaround is, to still use ASP.NET Membership (SqlMembershipProvider).

这篇关于SimpleMembership 与 ASP.NET MVC 4 中的自定义数据库架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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