Error after View being called

1

I have a login screen with the following call when the user clicks the "log in" button

$(document).ready(function(){
    $("#formLogin").on('submit', function (e) {
        e.preventDefault();
        var form = $(this);
        var mensagem = "Dados de Login inválidos.";
        var button = $('#btnEntrar');

        button.html("Validando...").attr("disabled", "disabled");
        if ($('#username').val() != "" && $('#password').val() != "") {
          $.ajax({
              url: '/Admin/Login',
              type: "POST",
              data: form.serialize(),
              success: function (resp) {
                $('#lblMsgAutenticacao').fadeOut(400);
                window.location = '/Admin/Inscricoes';
              },
              error: function (req, status, errorObj) {
                $('#lblMsgAutenticacao').html(mensagem).fadeIn(400);
                button.html("Entrar").removeAttr("disabled");
              },
              complete: function() {

                setTimeout(function(){
                  $('#lblMsgAutenticacao').fadeOut(400);
                }, 3000)
              }
          });
        }
        else {
          $('#lblMsgAutenticacao').fadeIn(400);
          button.html("Entrar").removeAttr("disabled");
        }

        if ($('#username').val() == "")
          $('#username').focus();
        else
          $('#password').focus();
    });
  });

This call leads to the method below:

[HttpPost]
public ActionResult Login(string username, string password)
{
    Usuario usuario = null;
    try
    {
       usuario = LoginBll.Valida(username, password);
       if (usuario == null )
          throw new Exception();
       else 
          Session["loginAdm"] = usuario;
    }
    catch (Exception e)
    {
          throw new Exception(e.Message, e);
    }
        return RedirectToAction("Inscricoes");    
   }

which in turn leads to the method:

 public ActionResult Inscricoes()
        {
            inscricoes_model.ViewModel.AdmInscricao admInscricao = null;
            try
            {
                admInscricao = new inscricoes_model.ViewModel.AdmInscricao();
                admInscricao.instituicoes = InstituicaoBll.Listar(null);
                return View(admInscricao);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }

        }

everything runs correctly without any error the view is called without any error in the code but the return of the ajax function is always error and does not redirect to the correct page. I can not identify where this error is, just say "Internal Server Error", any idea where to start?

    
asked by anonymous 01.12.2017 / 13:27

1 answer

1

A technique I use to detect call errors via ajax, is to simulate the direct call by the web browser to action .

In your case, you could make the request the following URL link passing a user and password of your system.

    
01.12.2017 / 13:48