Hemant Soni
Hemant Soni

Reputation: 2101

Membership.CreateUser() is giving this error "Specified method is not supported"

When I register new user using

Membership.CreateUser(model.UserId, model.Password, model.Email, null, null, true, null, out createStatus)

I am getting the following error:

Specified method is not supported

Please help

    [HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken]
    public ActionResult Register(RegisterModel model)
    {
        if (ModelState.IsValid)
        {
            // Attempt to register the user
            MembershipCreateStatus createStatus;
            Membership.CreateUser(model.UserId, 
                                  model.Password, 
                                  model.Email, 
                                  null, 
                                  null, 
                                  true, 
                                  null, 
                                  out createStatus);

            if (createStatus == MembershipCreateStatus.Success)
            {

                UpdateUserInfo();
                /* "False" for createPersistentCookie: */
                FormsAuthentication.SetAuthCookie(model.UserId, false);
                return RedirectToAction("Index", "Home");
            }
            else
            {
                ModelState.AddModelError("", ErrorCodeToString(createStatus));
            }
        }

        // If we got this far, something failed, redisplay form
        return View(model);
    }

Upvotes: 1

Views: 2392

Answers (3)

Jason Cidras
Jason Cidras

Reputation: 507

You're adding an additional null into your method call.

The method should be as followed:

Membership.CreateUser(model.UserId, model.Password, model.Email, null, null, true, out createStatus);

Here's the method signature:

public static MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, out MembershipCreateStatus status);

Hopes this helps!

Upvotes: 0

ChirpingPanda
ChirpingPanda

Reputation: 50

If you're trying to use ASP.NET Membership Provider for MVC4 (which is fair enough - you might have to access a legacy Membership Provider database which you don't have control over), you will need to turn SimpleMembership off (which is the default for MVC4).

Just add the following line to 'appSettings' in your Web.config:

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

Upvotes: 0

Pinch
Pinch

Reputation: 4207

You must now use WebSecurity.CreateUserAndAccount(...)

Upvotes: 2

Related Questions