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

-1

I'm doing a login screen in ASP.NET MVC. The framework makes all processes complete without errors: go to the database, query the login and return with an OK (user exists, I can authenticate). When the flow returns from the bank and passes through if (dados.OK) , it 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 can 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()
        }
    });
});
    
asked by anonymous 18.08.2016 / 04:16

1 answer

3

Basically, there is a lot wrong here.

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

A login authentication route should never be should be GET . GET is a method for passing parameters by URL. As a form, the correct method should be POST .

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

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

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