MVC 4 Simple Membership Provider and Entity Framework Migrations

So I have spent about 5-6 hours trying to figure out how to get EF Migrations working properly with MVC 4 when you are using the Seed method to insert initial data into your tables.

The issue is that when you enter some methods like this:

if (!Roles.RoleExists("Admin"))
if (Membership.GetUser("username", false) == null)
  WebSecurity.CreateUserAndAccount("username", "password");
  Roles.AddUserToRole("username", "Admin");
if (!Roles.IsUserInRole("username", "Admin"))
  Roles.AddUserToRole("username", "password");

Which is how most older examples which are available on the internet tell you to do it. The problem is when you try and use this with code migrations you get:

You must call the "WebSecurity.InitializeDatabaseConnection" method before you call any other method of the "WebSecurity" class. This call should be placed in an _AppStart.cshtml file in the root of your site.

So if you take and add this:

WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);

To your seed method, you get this:

To call this method, the "Membership.Provider" property must be an instance of "ExtendedMembershipProvider".

So the key to fixing that is that even though the built in forms authentication doesn’t use the settings in the web config (and will actually ignore it), you need to put some settings in there for EF Migrations to be configured properly.

So we add to the System.Web area of the Web.Config:

<roleManager enabled="true" defaultProvider="SimpleRoleProvider">
    <add name="SimpleRoleProvider" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData"/>
<membership defaultProvider="SimpleMembershipProvider">
    <add name="SimpleMembershipProvider" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData" requiresQuestionAndAnswer="false" />

And rerun the update-database command. It works now.

I hope this helps someone else to not spend all the time I was spending.

Tags: ,

Thursday, April 25th, 2013 Development 1 Comment

Ludum Dare 24 Post Mortem – Game-Age

The original post is here. This is a really late post, but I figured I should paste it to be consistent.

I had a great time this Ludum Dare. The theme threw me for a bit of a loop, like I’m sure it did to a lot of people, and I wasn’t sure I could commit to the weekend like I did last compo but I knew it would be fun so I was in. Plus, even if I didn’t succeed it would still be a learning experience, and who couldn’t use more of those?


I had a lot more knowledge coming into this ludum dare about what was possible in the time frame and what was going to eat up most of my time. My first LD entry I did in flash punk, and while I liked it I thought I would try something different and went with Construct 2 this time which is a great engine for fast prototyping. I think I would have liked using FlashPunk again but I need to sit down when I’m not in the middle of a compo and actually design a generic engine on top of it to make LD faster.

I wish I had a better way to do graphics. Right now I’m creating all my pixel art in Pixel Editor for android on my Asus Transformer and while it’s not bad, I’m a pretty bad artist and I need something that will allow me to make better looking art, even if its simple looking, faster. Although, I am getting faster at creating pixel art in the editor, I wouldn’t even know how to start animating them.


First, I knew when the theme was announced that Ididn’t want to create a game based on cells, or bacteria, or mutation. I figured those ideas would be beaten like a genetically altered dna consuming deceased horse. So I thought about evolution and what we where doing and came up with the idea for an evolving game, and even better, showing the evolution of classic arcade games. I think it turned out really well, especially near the end when I came up with the idea to go one step further and create a new game from the elements of all the previous games.

Construct 2 was an awesome choice for an engine. I never felt rushed, it did everything I wanted and I generally enjoyed using it.

SFXR, again for making arcade sounds easy. I was even able to make sounds I think closely resembled the arcade originals in a lot of cases.

Pixel Art Editor for Android, it’s free and is a great simple pixel art editor. It’s what I made every graphic in the game with except the Start and Replay buttons.

Having fun, because that’s what its all about, right?


Ludum Dare is awesome and I am glad I got to participate again. I’m glad I was able to finish my entry and I am happy with how it turned out. Please check it out! Especially if you like classic arcade games.

I reproduced 4 classic arcade games, evolving one into the other and finally evolving them all into a brand new game.


Friday, March 8th, 2013 Development, Gamedev, Ludum Dare, Postmortem No Comments

Studying nonstop.

I need to, and will, post more to this blog after the end of the month. I’m just studying nonstop to brush up before I take my certification tests to get my mcpd cert.
The prep book for WCF is incredibly dry and boring.

Tags: , ,

Saturday, June 23rd, 2012 Certification, Development, Update No Comments