SimpleMembership在ASP.NET MVC 4自定义数据库模式 [英] SimpleMembership with custom database schema in ASP.NET MVC 4

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

问题描述

我想启用ASP.NET MVC 4的SimpleMembership API来与我自己的数据库架构整合。我有一个简单明了的表在我的数据库名为用户这些字段:

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:

  • 编号
  • 名称
  • 密码
  • 电子邮件
  • 请将isDeleted
  • Id
  • Name
  • Password
  • Email
  • 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"                
                                 });

不过,密码字段(或它的哈希)没有插入到用户表(当然),它插入到被称为另一个表 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.

另外,我有另一种叫webpages_OAuthMembership,webpages_Roles和webpages_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调用将抛出一个异常,因为它会找不到webpages_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.

我的问题是:我该怎么办在这样的情况下,当我只想要一个简单的用户表,仅此而已。

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

我是否需要写全体成员处理和认证逻辑(散列code生成等)自己吗?

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成员(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天全站免登陆