Error Login Asp.net MVC

Asked

Viewed 107 times

1

I’m not able to validate my login, follow code below:

 public ActionResult Login(FormCollection collection)
    {
        AlunoAplicacao bdAluno;
        bdAluno = AlunoAplicacaoConstrutor.AlunoAplicacaoEF();

        var Aluno = bdAluno.ListarTodos().Select(x => x.Email == collection["Email"] && x.Senha == collection["Senha"]);

        if (Aluno.Count() == 1)
        {
            var AlunoOnline = Aluno.First();
            FormsAuthentication.SetAuthCookie(AlunoOnline.ID.ToString(), false);
            return RedirectToAction("AreaAluno");
        }

        else
        {
            return RedirectToAction("Resposta", new { id = "ErroLogin" });
        }

    }
  • What error is appearing??

1 answer

3


From what I understand you’re trying to go through the list with that lambda, so the correct way would be to use the where. Also, for you to get a reception of this login, you could pass the AlunoOnline.ID as a parameter of your RedirectToAction.

Follows code below:

  AlunoAplicacao bdAluno;
        bdAluno = AlunoAplicacaoConstrutor.AlunoAplicacaoEF();

        var Aluno = bdAluno.ListarTodos().Where(x => x.Email == collection["Email"] && x.Senha == collection["Senha"]);

        if (Aluno.Count() == 1)
        {
            var AlunoOnline = Aluno.First();
            FormsAuthentication.SetAuthCookie(AlunoOnline.ID.ToString(), false);
            return RedirectToAction("AreaAluno", new { id = AlunoOnline.ID });
        }

        else
        {
            return RedirectToAction("Resposta", new { id = "ErroLogin" });
        }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.