1
I have a login screen with the following call when the user clicka on the button "login"
$(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 way 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. can’t identify where this error is, just say "Internal Server Error", any idea where I can start ?
try calling http://localhost:port//Admin/Login directly in the browser? username=aaa&password=123 I just think you’ll have to change your login method to Httpget before. NOTE: puts a valid username and password in your call.
– Pablo Tondolo de Vargas
Cara helped a lot, I used the full url for the page that the method redirects and found some errors in it that I could fix, thanks.
– user2913044
Add your solution to see what’s been done.
– Pablo Tondolo de Vargas
You came to modify to Httpget the login method?
– Pablo Tondolo de Vargas
no, with the same post worked, the problem is that in a partialView that had on the page he tried to use an object that was removed from the system, when I removed this part of the partialView worked, I just found it strange that the error did not appear before and straight compile the program without error. But what I changed was this in the partial view. @{ if (Session["loginAdm"] == null) { Response.Redirect(Url.Action("Index", "Admin")); } subscription_model.Login = (subscription_model.Login)Session["loginAdm"]; <----- this object no longer exists on the system, was soh remove him }
– user2913044