I have an MVC 4 EF web project with a code-first sql server db that very closely follows the basic and usual structure of any you would see as an example anywhere on the web.
I have read EVERY article posted on the internet concerning how to do what I need and none of them so far make any difference to my situation. I am not doing anything extraordinary, I just took out the 'Register' new user capability as needed by my project, and am trying to create a couple of users as login points by including them in the Migrations/Configuration.cs file like this:
protected override void Seed (EntityContext context)
{
if (!WebSecurity.Initialized)
WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
if (!Roles.RoleExists("Administrator"))
Roles.CreateRole("Administrator");
if (!WebSecurity.UserExists("Owner"))
WebSecurity.CreateUserAndAccount("Owner", "password");
if (!Roles.GetRolesForUser("Owner").Contains("Administrator"))
Roles.AddUsersToRoles(new[] { "Owner" }, new[] { "Administrator" });
if (!WebSecurity.UserExists("fred"))
WebSecurity.CreateUserAndAccount("leemid", "pw");
if (!Roles.GetRolesForUser("leemid").Contains("Administrator"))
Roles.AddUsersToRoles(new[] { "leemid" }, new[] { "Administrator" });
base.Seed(context);
}
Everything works beautifully locally, but when I publish to my Azure account, where everything is set up properly as near as I can tell, the app appears correctly except that I can't login as my seeded user. I have connected to my Azure db using SQL Management Studio and all of the UserProfile and webpages_ tables are there, the app specific ones are not because the code-first hasn't had a chance to build the yet (I assume), but there are no users or roles. Locally, everything is built and populated as expected.
I have added the often suggested code in the root Web.config file thus:
<system.web>
<roleManager enabled="true" defaultProvider="SimpleRoleProvider">
<clear/>
<add name="SimpleRoleProvider" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData"/>
</providers>
</roleManager>
<membership defaultProvider="SimpleMembershipProvider">
<clear/>
<add name="SimpleMembershipProvider"
type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData"/>
</providers>
</membership>
It certainly took all of this to accomplish successful publishing of the site, but I am frustrated by the lack of success in seeding the users. Any one solved this already?
Комментариев нет:
Отправить комментарий