Redirect users not indexed Asp.net

Asked

Viewed 102 times

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 anyone who is logged in with the following description [Authorize(Roles = "Lojista")] the login part of the system was not I who made, so I am with a little difficulty of intender the functioning, and when I look for something about I can not mean very well.

I saw that some people set some things on the web.config, but I couldn’t understand it. In case you need more information and just say.

  • What is your system? MVC or webforms? ado.net or entityframework? made using Identity, Membership or in-race login system?

  • I’ll improve the question...

  • My lack of notion hinders the preparation of the question, I hope to intender, but as it was not I who logged in I do not know how it works, because I was told that the redirection was done on the web.config when they did not index the user, but I didn’t find anything there that related to this.

  • now it’s much clearer, I’ll answer the question

1 answer

1


To redirect pages that will be authenticated using the attribute [Authorize] just configure your web.config for that reason.

Web.Config

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

</system.web>

Oauth Note that system like Identity, configure the default login url through a file called Starup.Auth.cs inside the briefcase App_start Something like:

LoginPath = new PathString("/MeuUsuario/Login")
  • 1

    Man, exactly what I needed, simple and direct, I spent a lot of time looking and just didn’t think, thank you so much for the patience and the good will helped me a lot.

Browser other questions tagged

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