Note that there are some explanatory texts on larger screens.

plurals
  1. POSeeding Membership in Windows Azure using Entity Framework
    primarykey
    data
    text
    <p>I'm trying to get Membership roles being created in my SQL Azure database using ASP.NET MVC 4 and Entity Framework 5. I can get this to work just fine on my local host, but it doesn't seem to create the accounts nor the membership roles on Azure. Note that I'm also using Fluent NHibernate but I believe this is unrelated.</p> <p>In my Application_Start() function I initialize the database to make sure all the tables exist:</p> <pre><code>WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true); </code></pre> <p>I also created a SeedMembership() function (called by the Seed() function in Migrations\Configuration.cs) that looks like this:</p> <pre><code>private void SeedMembership() { WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true); var roles = (SimpleRoleProvider)Roles.Provider; var membership = (SimpleMembershipProvider)Membership.Provider; if (!roles.RoleExists("Administrator")) { roles.CreateRole("Administrator"); } if (membership.GetUser("TestAccount", false) == null) { membership.CreateUserAndAccount("TestAccount", "testpwd"); } if (!roles.GetRolesForUser("TestAccount").Contains("Administrator")) { roles.AddUsersToRoles(new[] { "TestAccount" }, new[] { "Administrator" }); } } </code></pre> <p>Using update-database in the package manager console I can see that the Seed method is being called. I even ran this command using the actual SQL Azure connection string:</p> <pre><code>PM&gt; Update-Database -StartUpProjectName "MyProject" -ConnectionString "Data Source=tcp:myDB.database.windows.net,1433;Initial Catalog=myDB;User Id=myUser@myDB;Password=myPwd" -ConnectionProviderName "System.Data.SqlClient" Specify the '-Verbose' flag to view the SQL statements being applied to the target database. Applying code-based migrations: [201212251057032_Initial]. Applying code-based migration: 201212251057032_Initial. Running Seed method. PM&gt; </code></pre> <p>But even like this my "Administrator" account is not created. I know because I added a check in my view:</p> <pre><code>@if(User.IsInRole("Administrator")) { &lt;li&gt;@Html.ActionLink("Admin", "Index", "Admin")&lt;/li&gt; } </code></pre> <p>And the "Admin" link never shows up when trying on Azure, but works just fine locally.</p> <p>Is there a way for me to troubleshoot what's going on? Am I even trying this correctly?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload