Redirect non-indeterminate users to Asp.net

0

I have an ASP.NET MVC page, using entityframework, and I have a login system:

  public ActionResult Index(LoginModel model)
    {
        if (ModelState.IsValid)
        {
            try
            {
                if (Membership.ValidateUser(model.Email, model.Senha))
                {
                    Pessoa pessoa = this.PessoaServico.GetMany(p => p.Email == model.Email).First();

                    if (pessoa is Lojista)
                        return RedirectToAction("Index", "Dashboard", new { area = "Lojista" });
                }
            }
            catch (Exception e)
            {

                ModelState.AddModelError("erro", "Ocorreu um erro inesperado");
            }

        }

        ModelState.AddModelError("erro", "Usuário e/ou Senha Inválidos.");

        return View(model);
    }

I only authorize who is logged in with the following description [Authorize(Roles = "Lojista")] the login part of the system was not me that did, so I have a bit of difficulty to understand the operation, and when I look for something about I can not understand very well .

I saw some things stick in web.config, but I could not figure it out. If you need more information, just say it.

    
asked by anonymous 26.09.2016 / 19:51

1 answer

1

To redirect the pages that will be authenticated using the [Authorize] attribute, just set your web.config to this.

Web.Config

<system.web>
<authentication mode="Forms">
      <forms loginUrl="~/Login/Index" timeout="2880" />
</authentication>

</system.web>

OAuth Note that system like Identity, set the default login url through a file named Starup.Auth.cs within the App_start Something like:

LoginPath = new PathString("/MeuUsuario/Login")
    
26.09.2016 / 20:59