Location.href is not transferring me from ASP.NET MVC page

Asked

Viewed 372 times

-1

I am making a login screen in ASP.NET MVC. The framework does all the complete processes without errors: goes to the database, queries the login and comes back with an OK (user exists, I can authenticate). When the flow comes back from the bank and goes through if (dados.OK), he has to throw me to another page, but this is not happening: simply the browser runs the code and does not throw me to the other page (_ViewStart)

What could it be? A better way? Tips?

$(document).ready(function () {
$("#status").hide();
$("#btLogar").click(function () {
    $.ajax({
        data: { Login: $("#txtLogin").val(), Senha: $("#txtSenha").val() },
        dataType: "json",
        type: "GET",
        url: "/Login/AutenticarLogin",
        async: true,
        beforeSend: function () {
            $("#status").html("Estamos autenticando o usuário... Só um instante.");
            $("#status").show();
        },
        success: function (dados) {
            if (dados.OK) {
                $("#status").html(dados.Mensagem)
                setTimeout(function () { window.location.href = "_ViewStart" }, 5000);
                alert("logado");
                $("#status").show();
            }
            else {
                $("#status").html(dados.Mensagem);
                $("#status").show();
            }
        },
        error: function () {
            $("#status").html(dados.Mensagem);
            $("#status").show()
        }
    });
});
  • Start by seeing and posting the btLog button,

  • I don’t understand....

1 answer

3


Basically, there’s a lot of things wrong here.

_ViewStart is not a View represented by a route. Therefore, it cannot be called by JS.

A login authentication route never should be GET. GET is a method to pass parameters through URL. Since it is a form, the correct method should be POST.

I do not know how the logic of authentication is, but I believe that there is no setting of cookies or security objects that block the user when he tries to access any other route of his system.

Still, if you really want to continue this approach, the right one would be:

setTimeout(function () { window.location.href = "/Home" }, 5000);

Browser other questions tagged

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