【发布时间】:2013-05-28 20:32:37
【问题描述】:
我的应用程序是一个 MVC4 应用程序,其域模型是在 EF 5 Code First 中创建的。该应用程序需要身份验证/授权,我想使用默认的 ASP.NET Membership Provider。
考虑到这一点,我继续使用 aspnet_reqsql 实用程序添加 ASP.NET 默认成员资格提供程序所需的所有表。
但是,我的应用程序需要存储的用户信息比成员资格提供者默认提供的信息更多。例如:
- 名字
- 姓氏
- 出生日期
- 地址(分成不同的 列)
这些东西不存在于成员资格提供者表中。所以我继续将所有缺失的列添加到 users 表中,还创建了一个 Addresses 表,并创建了 User 和 Address 之间的关系。
然后我进入我的注册视图模型,添加缺失的数据字段,然后进入 AccountController 并检查注册用户时调用的方法。是这样的:
//
// Summary:
// Creates a new user profile entry and a new membership account.
//
// Parameters:
// userName:
// The user name.
//
// password:
// The password for the user.
//
// propertyValues:
// (Optional) A dictionary that contains additional user attributes. The default
// is null.
//
// requireConfirmationToken:
// (Optional) true to specify that the user account must be confirmed; otherwise,
// false. The default is false.
//
// Returns:
// A token that can be sent to the user to confirm the user account.
//
// Exceptions:
// System.InvalidOperationException:
// The WebMatrix.WebData.SimpleMembershipProvider.Initialize(System.String,System.Collections.Specialized.NameValueCollection)
// method was not called.-or-The Overload:WebMatrix.WebData.WebSecurity.InitializeDatabaseConnection
// method was not called.-or-The WebMatrix.WebData.SimpleMembershipProvider
// membership provider is not registered in the configuration of your site.
// For more information, contact your site's system administrator.
public static string CreateUserAndAccount(string userName, string password, object propertyValues = null, bool requireConfirmationToken = false);
这种方法让我很困惑!我期待看到数据插入数据库的逻辑,以便我可以编辑它并添加使该方法也处理我新添加的字段,但所有这些都丢失了!
我错过了什么?如何实现我想要的注册类型?
【问题讨论】:
标签: asp.net-mvc-4 ef-code-first asp.net-membership