title: WebSecurity vs FormsAuthentication in ASP.NET MVC4
body: <p>I guess I am trying to mix two providers in project but I am looking to use websecurity in conjunction to my forms authentication. I need websecurity for OAUTH authentication using Facebook, and google.</p>
  
  <p>The error that I am getting when I try to login using facebook is </p>
  
  <p>To call this method, the <code>Membership.Provider</code> property must be an instance of <code>ExtendedMembershipProvider</code>.</p>
  
  <p>Here are the code samples. How can I use both?</p>
  
  <pre><code>public ActionResult ExternalLoginCallback(string returnUrl)
          {
              AuthenticationResult result = OAuthWebSecurity.VerifyAuthentication(Url.Action("ExternalLoginCallback", new { ReturnUrl = returnUrl }));
              if (!result.IsSuccessful)
              {
                  return RedirectToAction("ExternalLoginFailure");
              }
  
              if (OAuthWebSecurity.Login(result.Provider, result.ProviderUserId, createPersistentCookie: false))
              {
                  return RedirectToLocal(returnUrl);
              }
  
              if (User.Identity.IsAuthenticated)
              {
                  // If the current user is logged in add the new account
                  OAuthWebSecurity.CreateOrUpdateAccount(result.Provider, result.ProviderUserId, User.Identity.Name);
                  return RedirectToLocal(returnUrl);
              }
              else
              {
                  // User is new, ask for their desired membership name
                  string loginData = OAuthWebSecurity.SerializeProviderUserId(result.Provider, result.ProviderUserId);
                  ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(result.Provider).DisplayName;
                  ViewBag.ReturnUrl = returnUrl;
                  return View("ExternalLoginConfirmation", new RegisterExternalLoginModel { UserName = result.UserName, ExternalLoginData = loginData });
              }
          }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>public ActionResult Login(LoginModel model, string returnUrl)
      {
          if (ModelState.IsValid)
          {
              if (Membership.ValidateUser(model.UserName, model.Password))
              {
                  FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                  if (Url.IsLocalUrl(returnUrl))
                  {
                      return Redirect(returnUrl);
                  }
                  else
                  {
                      return RedirectToAction("Index", "Home");
                  }
              }
              else
              {
                  ModelState.AddModelError("", "The user name or password provided is incorrect.");
              }
          }
  
          // If we got this far, something failed, redisplay form
          return View(model);
      }
  </code></pre>