Entity Framework Code First and WebMatrix membership -


i started new project entityframework 5.0 code first automatic migration , mvc4 simple membership.

and modified configuration.cs following:

        protected override void seed(userscontext context)         {             if (!websecurity.initialized)             {                 websecurity.initializedatabaseconnection("defaultconnection", "users", "userid", "username", true);             }             console.writeline("initialized websecurity");             createuser("admin");             createuser("radu");             createuser("mariana");         }          private static void createuser(string username)         {             if (!websecurity.userexists(username))             {                 websecurity.createuserandaccount(username, "123456");             }             else             {                 membership.deleteuser(username);                 websecurity.createuserandaccount(username, "123456");             }         } 

web.config entries :

    <authentication mode="forms">       <forms loginurl="~/account/login" timeout="2880" />     </authentication>     <rolemanager enabled="true" defaultprovider="simpleroleprovider">       <providers>         <clear/>         <add name="simpleroleprovider" type="webmatrix.webdata.simpleroleprovider, webmatrix.webdata"/>       </providers>     </rolemanager>     <membership defaultprovider="simplemembershipprovider">       <providers>         <clear/>         <add name="simplemembershipprovider"              type="webmatrix.webdata.simplemembershipprovider, webmatrix.webdata"/>       </providers>     </membership> 

error message: user name or password provided incorrect.

unfortunately after migration when try log in 1 of users inserted in db, invalid log in message. why , how should fix this?

i have found problems:

protected override void seed(handmade.web.models.userscontext context) {     if (!websecurity.initialized) {         //websecurity.initializedatabaseconnection("defaultconnection", "users", "userid", "username", true);          // used wrong init seed method         websecurity.initializedatabaseconnection("defaultconnection", "userprofile", "userid", "username", true);     }     console.writeline("initialized websecurity");     createuser("admin");     createuser("radu");     createuser("mariana"); }  private static void createuser(string username) {     if (!websecurity.userexists(username)) {         websecurity.createuserandaccount(username, "123456");     } else {         membership.deleteuser(username);         websecurity.createuserandaccount(username, "123456");     } } 

also corrected init filter attribute used:

private class simplemembershipinitializer         {             public simplemembershipinitializer()             {                 //database.setinitializer<userscontext>(null);                  try                 {                     using (var context = new userscontext())                     {                         if (!context.database.exists())                         {                             // create simplemembership database without entity framework migration schema                             ((iobjectcontextadapter)context).objectcontext.createdatabase();                         }                     }                      websecurity.initializedatabaseconnection("defaultconnection", "userprofile", "userid", "username", autocreatetables: true);                 }                 catch (exception ex)                 {                     throw new invalidoperationexception("the asp.net simple membership database not initialized. more information, please see http://go.microsoft.com/fwlink/?linkid=256588", ex);                 }             }         } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -