How does Membership.ValidateUser method access a database?

user2923864 picture user2923864 · Jan 6, 2015 · Viewed 11.8k times · Source

I wanted to build a membership system at the beginning of my MVC project and I used Membership.ValidateUser method to verify credentials. However I could not understand how does this method access my database and check my email and password informations.

[HttpPost]
[ActionName("Login")]
public ActionResult Login(LoginModel loginModel)
{
        if (Membership.ValidateUser(loginModel.Email, loginModel.Password))
        {
            FormsAuthentication.SetAuthCookie(loginModel.Email, true);
            return Json(true);
        }

        return new JsonNetResult() 
        { Data = new { Error = true, Messages = new[] { new { Message = "Wrong username or password" } } } };
}

Answer

Perfect28 picture Perfect28 · Jan 6, 2015

It' used the MembershipProvider specified on your Web.config file to validate the user. By default, it uses DefaultMembershipProvider