我的任务是从旧的半生不熟的用户商店(使用加密密码)迁移到默认的MS会员/角色提供商。我在其他项目中做到这一点没有问题。
在这种情况下,我使用代码优先创建必要的表与'new'.NET通用提供程序。我只是尝试将新记录插入到Users表中,并且遇到了问题。
我有一个简单的edmx,其中包含由成员资格提供者创建的6个表。我已经设置了我的web.config以指向必要的cxn字符串&会员/角色提供者(以下代码)。
Web.Config:
<connectionStrings>
<add name="Test" connectionString="metadata=res://*/Entities.Test.csdl|res://*/Entities.Test.ssdl|res://*/Entities.Test.msl;provider=System.Data.SqlClient;provider connection string="data source=[OurServer];initial catalog=[OurDb];integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>
<membership defaultProvider="DefaultMembershipProvider">
<providers>
<add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider" connectionStringName="Test" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
</providers>
</membership>
<roleManager enabled="true" defaultProvider="DefaultRoleProvider">
<providers>
<add connectionStringName="Test" applicationName="/" name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider" />
</providers>
</roleManager>
这是我的“更新密码”功能:
System.Web.Security.MembershipCreateStatus status = new System.Web.Security.MembershipCreateStatus();
//Get list of existing users, containing Username & encrypted PW
List<UserMigration.Models.Users> usersList = UserMigration.Models.Users.GetUsers();
foreach (var user in usersList)
{
string password = "";
//We have two encryption methods (bogus I know), so I attempt to decrypt with one, then another, using existing utility functions.
if (!EncryptDecrypt.TryDecryptTripleDES(user.Password, out password))
{
EncryptDecrypt.TryDecrypt(user.Password, out password);
}
//if we got a password, lets party
if (!string.IsNullOrEmpty(password))
{
System.Web.Security.Membership.CreateUser(user.Username, password,string.Empty,null,null,true,out status);
}
}
我在CreateUser调用时遇到错误,我不能为我的生活找出原因。我没有以任何方式修改实体。这应该很简单。错误是:
Schema specified is not valid. Errors:
The relationship 'TestModel.MembershipEntity_Application' was not loaded because the type 'TestModel.Membership' is not available.
The relationship 'TestModel.RoleEntity_Application' was not loaded because the type 'TestModel.Role' is not available.
The relationship 'TestModel.User_Application' was not loaded because the type 'TestModel.User' is not available.
The following information may be useful in resolving the previous error:
The required property 'Roles' does not exist on the type 'System.Web.Providers.Entities.User'.