asp.net mvc 4 - You must call “WebSecurity.InitializeDatabaseConnection” exception when I already have -


so i'm trying seed database following initializer

public class dbinitializer : dropcreatedatabasealways<iamcontext> {     protected override void seed(iamcontext context)     {          websecurity.initializedatabaseconnection("iamcontext",           "userprofile", "userid", "username", autocreatetables: true);         var roles = roles.provider;         var membership = membership.provider;          if (!roles.roleexists("admin"))         {             roles.createrole("admin");         }         if (!websecurity.userexists("test"))         {             websecurity.createuserandaccount("test", "password");         }          if (!roles.getrolesforuser("test").contains("admin"))         {             roles.adduserstoroles(new[] { "test" }, new[] { "admin" });         }          context.products.add(new product         {             id = 1,             name = "homunculi",             price = 85,             longdescription = "happens when failed human transmutations occur",              shortdescription = "failed xmute",              media = "cd"         });           base.seed(context);     } } 

i exception have call websecurity.initializedatabaseconnection first. looks have i'm little confused. great. should mention i'm new webforms authentication. understanding , answers!

check out article on seeding , customizing simplemembership. may give hints on proper initialization of simplemembership database. article discusses modifying how simplemembership initialized more straight forward using initializesimplemembershipattribute. need have call initialize database in couple of places because seeding not occur , needs in seed method work. safe method first check if has been initialized before call shown in following code snippet.

  if (!webmatrix.webdata.websecurity.initialized)       webmatrix.webdata.websecurity.initializedatabaseconnection("simplesecurityconnection",           "userprofile", "userid", "username", autocreatetables: true); 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -