创建数据库时,我尝试使用下面的seed方法创建一个用户:
protected override void Seed(CodingCraftMod1Ex4AuthMembershipContext context)
{
string password = PasswordsHelper.EncodePassword("123456", System.Web.Security.MembershipPasswordFormat.Hashed);
var user = new CustomUser
{
CustomUserId = Guid.NewGuid(),
Name = "MyUser",
CreatedOn = DateTime.Now,
LastModified = DateTime.Now
};
context.CustomUsers.Add(user);
context.SaveChanges();
var membership = new Membership
{
MembershipId = Guid.NewGuid(),
CustomUser = user,
Password = password,
CreatedOn = DateTime.Now,
LastModified = DateTime.Now,
};
context.Memberships.Add(membership);
context.SaveChanges();
}
但是我得到这个错误:
自动生成的密钥不支持哈希密码或加密密码
我已经found this question in SO。但是我已经在使用machineKey元素,像这样:
<machineKey validationKey="13687AD58719815734D5ECA97AADA159F4084FE994E32192243818A714DD6BC763B9F3D8AE7B3A7858A268D8EAAB37BF5031E77E5971C82BC1ACEA478C76C6CF"
decryptionKey="A39F3B62B3CAAD3F75358197CA1D880BA3F392BE79AE4E91D2A09219D82A6978"
validation="SHA1"
decryption="AES" />
我使用this online tool生成密钥。