Error Login Asp.net MVC

1

I can not validate my login, follow the 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" });
        }

    }
    
asked by anonymous 13.01.2015 / 17:49

1 answer

3

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

Follow the 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" });
        }
    
13.01.2015 / 17:51