-2

i try to make simple custom membership provider to my application. i try to use login function to login to my application

whats wrong with my code? why is not redirect to home?/

[HttpPost]
public ActionResult Login(string UserName, string UserPassword)
{
    if (Membership.ValidateUser(UserName, UserPassword))
    {
        return RedirectToAction("Index");
    }

    return View();
}

public override bool ValidateUser(string username, string password)
{
    if (username == "admin" && password == "1234")
    {
        return true;
    }
    else
    {
        return false;
    }
}

can someone tell me, which part is wrong??

4

2 に答える 2

2

これを試して:

return RedirectToAction("Index", "Home");

代わりに:

return RedirectToAction("Index");
于 2013-06-19T10:10:10.213 に答える
0
public override bool ValidateUser(string username, string password)
        {

            XNetEntities db = new XNetEntities();
            int count = db.Users.Count(r => r.UserName == username && r.UserPassword == password);
            if (count > 0)
            {
                FormsAuthentication.SetAuthCookie(username, true);
                return true;
            }
            else
            {
                return false;
            }
        }



 [HttpPost]
        public ActionResult Login(User user)
        {
            if (Membership.ValidateUser(user.UserName, user.UserPassword))
            {
                return RedirectToAction("Index");
            }

            return View(user);
        }
于 2013-06-19T10:21:30.003 に答える