Reputation: 6434
I have read a number of links to try and help me solve this problem. I am following my first MVC tutorial through on Pluralsight and I am moving on to using authentication. It uses the MVC4 Internet Application Template.
In my Seed
method I have:
protected override void Seed(DepartmentDb context)
{
if (!Roles.RoleExists("Admin"))
Roles.CreateRole("Admin");
if (Membership.GetUser("Luke") == null)
{
Membership.CreateUser("Luke", "password");
Roles.AddUserToRole("Luke", "Admin");
}
}
The user and role add fine in to SQL
and this all seems hunky dory, and is also the same as the tutorial. It then instructs to log in with my credentials. So I try to log in and I get the exception stated in the title:
Membership.Provider must be instance of ExtendedMembershipProvider
I have tried re-installing the packages required and also tried installing it as per a SO post and also adding the SimpleMembership
into appsetings
which doesn't work.
I have also read this MSDN link as per a comment, which I have followed instructions but still can't solve it.
What else do I need to do to get this working? It is driving me insane.
Thanks,
Luke.
Upvotes: 0
Views: 709
Reputation: 93424
The problem here is that you are calling Membership.CreateUser()
prior to the SimpleMembershipProvider being initialized. This is initialized via an attribute on the AccountController (which is typically loaded when the user logs in, because the login functions are part of the AccountController.
Unfortunately, your seed function runs before the AccountController is accessed, and thus, the provider is not yet initialized.
Look at the InitializeSimpleMembershipAttribute.cs class, and figure out a way to call this before your seed function runs.
Upvotes: 1