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

Veronica Mars Kickstarter

The Veronica Mars Kickstarter is pretty amazing. It hit 1 million in just under 5 hours and hit it’s goal in just under 12. While that goes to show you that there is still a rabid fanbase behind the IP, who is really gaining from the project?

Initially you would say the fans. They get access to something they never would have gotten had it not been for the Kickstarter. However, I think it’s really the movie distributor that is looking to benefit the most from this project and while it seems like a great way to further a franchise that was dead I think it’s just going to cause the movie studios to reject more movies.

The way a movie normally gets made is someone pitches an idea or writes a script and they shop around to the studios to find one willing to take the risk on the movie. The movie gets picked up, the studio puts out the money, and the movie gets made. They then distribute it to theatres and try to recoup their losses in ticket sales and dvd and other merchandising sales.

Now the paradigm has changed: The studio isn’t backing the project, the fans are. So now instead of putting their necks out there they get the fans to pay for it, the movie gets made and then the studio/distributor tries to recoup their losses in ticket sales and dvds. Wait though, they have minimal if any losses because they didn’t pay for the project, they have guaranteed dvd sales because of the Kickstarter. The movie is even being advertised for free. Why wouldn’t they want that? It’s all profit for the studio at that point.

Don’t get me wrong, I love Veronica Mars and I’m glad it’s getting made. My only issue is that it’s setting a precedent. Any movie that the studios think is marginal they are going to offer a “distribution” deal if they get the money another way. Cue Kickstarter. There’s no reason for them not to do it.


Friday, March 15th, 2013 Uncategorized No Comments

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

Holy spam batman.

So I haven’t posted anything to my blog in quite a few months. I came back and there are 419 spam messages. A welcome greeting.

That’s a whole lot of spam for a blog with like 3 posts on it.

I’ve been extremely busy lately with school, changing jobs but I hope to post more on this blog. I have a lot of technical things I’d like to write about so maybe I will work some of that out.

In other news I have a new job, I moved to Las Vegas and got a job as a Software Engineer with Structure Studios. I’m loving it so far, it’s a great company with a great product.

More later.

Friday, March 8th, 2013 Life, Update 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

Tiny God Postmortem Addendum

My original Postmortem is here.

Since LD submission and I released my game I’ve found that I learned a lot of additional things from the reviews I’ve gotten.

Even if you put an Instructions link on the first screen of the game, people won’t click it and then will ask how to win your game.

I’m not sure how to solve this one except to somehow reveal the win condition during play, or if this is something to be worried about.

Even if you think your instructions are informative enough about your game, they probably arent.

I included a mini tutorial system in my game to guide the player through playing and instructions but I still didn’t include enough info. I should have had more friends play test the game when it was near submission time so I could polish these things more.

If you have random enemy generation, make sure it’s right.

I had a really stupid bug in my submission build for my enemy wave generator, I didn’t realize it until people started commenting how easy the waves where. I went back and found the bug right away.

If you build a web based game, don’t just link to the game itself, but embed it in a page with more info.

This one I just kind of realized. I ran out of time at the end and just posted a link right to the swf file instead of making a simple page to embed it in so I could put FAQ or other information in front of the player in case they are linked to it from places other than LD.

Anyway, I just thought others might want to learn from my mistakes. You can find my game here. I’ve also added a link for a Work In Progress version with bug fixes and updates suggested by players.

Thanks for reading!

Tags: , , , ,

Friday, April 27th, 2012 Gamedev, Ludum Dare, Postmortem No Comments

Ludum Dare #23 PostMortem – Tiny God : Small Diety, Big Pantheon

This is a postmortem from my Ludum Dare entry. I decided I should move it over here. The original post is here

I had an amazingly fun time participating in Ludum Dare. This was my first and I’m incredibly happy with what I have accomplished. I havent written a complete game in some time and doing this was just the jump start I needed I think. So here are some of the things that worked, some that didn’t and where I go from here.


I wish I had better researched my intended platform beforehand. I decided to do LD about 4  days before hand and settled on FlashPunk 2 days before the start. Never having done any work with flash before I wish I had researched the graphic and sound formats that were importable and what the limitations were.

In addition to that, I wish I had better resources for converting files, especially sound. I wasted at least an hour, probably 2 or 3 just finding programs and websites to convert sounds back and forth to different formats.

I wish I had planned the weekend out better. I had a concert in Vegas (3 hour round trip) to attend saturday night, and 2 BBQs on sunday, all of which cut significantly into my time. I don’t regret any of my activities, just my planning.

I wish I had come up with the storyline for my game sooner so I could have built in more than one level. I ended up not being able to include more than a single level because I came up with a more involved story saturday night, and by then it would have taken code refactoring to allow me to reuse assets in the way that I wanted to carry the story.


FlashPunk, it’s awesome. I had no experience with flash and made a game in 48 hours. Also Punk.UI. Caveat: I’ve been programming in multiple languages for over 20 years.

SFXR, it also rocks, it allowed me to add sound where I never would have made any kind of effects before.

GreaseMonkey and his AutoTracker-BU. Autogenerated music? Awesome.

Pixel Art Editor for Android. I used this on my Asus Transformer to make most of the pixel art. My “art” has always been the definition of programmer art, but I am proud of what I accomplished.

Making something different. When the theme was announced I wrote down a bunch of ideas that I thought were obvious and then told myself I couldn’t do any of them. Everyone was going to do a certain list of games and I wanted to do something different. I think I accomplished that.

Using a tool that allowed me to iterate rapidly. I think this is huge. Being able to make a change and see the change almost instantly was key. Especially when I was making a bunch of AI controlled entities.

Keeping my scope small and manageable. This was also a big thing, I threw away a bunch of ideas I thought were cool, but knew there was no way I could complete in 48 hours with no outside assets.

Lastly, but not least. Having an awesome girlfriend who is supportive of what I want to do and also likes to playtest (Sometimes too much!).




Monday, April 23rd, 2012 Flash, FlashPunk, Gamedev, Ludum Dare, Postmortem, Tools No Comments