Problem with page return according to C#profile

Asked

Viewed 102 times

1

I am trying to return a page according to the user profile registered in the bank. If his profile is "Admin" returns another page. I try with the Administrator profile and it works, already of another user, I changed his profile in the bank and does not return the right profile.

Can someone help me ? My code is this:

 public ActionResult LogOn(FormCollection f, string returnUrl)
        {
            Conta user = new Conta();
            ContaModels atrrConta = new ContaModels();
            atrrConta = user.RetornaUser(f["login"]);
            if (user.AutenticaUser(atrrConta, f["senha"]))
            {
                //Rotina para autenticar usuario
                if (returnUrl == "" || returnUrl == null)
                {
                    returnUrl = "../CalendarioAlertaSMS";
                }
                System.Web.Security.FormsAuthentication.SetAuthCookie(f["login"], false);

                Session["PERFIL"] = atrrConta.Ide_Perfil;
                if (Session["PERFIL"].ToString() == "ADMIN")
                {
                    returnUrl = "../PainelAdm";
                }

                return Redirect(returnUrl);
            }
            else {
                ViewBag.Message = "Login ou senha inválidos.";
                return View(); 
            }
        }

1 answer

2


tries to use this in place of redirect:

return RedirectToAction("NomeDaAction");
  • This method does not appear to me here not @Rafael Cabral.

  • 1

    returns any errors? if it still doesn’t workVoce can use 'Return View("nameAction")'

  • It’s just that I’m starting in MVC now, just manjo de webforms. rs

  • rs, an example for you to better understand: return RedirectToAction("Details"); ai it will return to the actionresult Details control

  • I tried, only he doesn’t recognize Redirecttoaction. Need to import some library ?

Browser other questions tagged

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