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

I am facing this error, and I cannot figure it out. I send data to my controller through PostMan in Chrome, reaching the CreateUserAndAccount method and getting this error:

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

Here is my controller:

 [System.Web.Http.Authorize] [InitializeSimpleMembership] public class AccountController : ApiController { // POST: /api/register [System.Web.Http.HttpPost] [System.Web.Http.AllowAnonymous] [ValidateAntiForgeryToken] //public HttpResponseMessage Register(RegisterModel model, string returnUrl) public HttpResponseMessage Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user try { WebSecurity.CreateUserAndAccount(model.UserName, model.Password); // blows up here WebSecurity.Login(model.UserName, model.Password); 

I use the same InitializeSimpleMembershipAttribute class as the MVC SPA template:

 { [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] public sealed class InitializeSimpleMembershipAttribute : ActionFilterAttribute { private static SimpleMembershipInitializer _initializer; private static object _initializerLock = new object(); private static bool _isInitialized; public override void OnActionExecuting(ActionExecutingContext filterContext) { // Ensure ASP.NET Simple Membership is initialized only once per app start LazyInitializer.EnsureInitialized(ref _initializer, ref _isInitialized, ref _initializerLock); } private class SimpleMembershipInitializer { public SimpleMembershipInitializer() { Database.SetInitializer<UsersContext>(null); try { using (var context = new UsersContext()) { if (!context.Database.Exists()) { // Create the 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 could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex); } } } } } 

And in my web.config, I included simpleMembership:

 <add key="enableSimpleMembership" value="true" /> 

What else could be?

Edit: I just tried the tip found at this link:

http://insomniacgeek.com/to-call-this-method-the-membership-provider-property-must-be-an-instance-of-extendedmembershipprovider/

And now I get

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

Any suggestions would be great.

+3
source share
1 answer

I found a problem. I referenced System.Web.MVC in my InitializeAttribute class ... it should have been System.Web.Http.

-one
source

Source: https://habr.com/ru/post/1495271/


All Articles