Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello friends I go to the login.controller file from the login.js file, if the password is correct, I redirect to the home page.However, although it is redirected to the home page, the home page does not open, login.js falls into the error block and gives a json error.json.I do not parse.I only create Session.If the sessionID in the database is the same, I open the home page.thanks I have not found it for 2 days.

login.js file
JavaScript
function Login() {
var mail = $("#mail").val();
var password = $("#password").val();

if (mail == null || password == null) {
    var dialog = bootbox.dialog({
        title: "Uyarı",
        message: "<label class='control-label'>invalid mail or password</label>",
        size: 'small',
        locale: 'tr',
        onEscape: true,
        buttons: {
            ok: {
                label: 'Tamam',
                className: 'btn-default',
                callback: function (result) {

                    runKey = false;
                }
            }
        }, onEscape: function (result) {
            runKey = false;
            return false;
        }
    });
}
else {
    user = {};
    user["MAIL"] = mail;
    user["PASSWORD"] = password;

    $.ajax({
        url: '/Login/Login',
        type: 'POST',
        dataType: 'json',
        contentType: 'application/json; charset=utf-8',
        async: false,
        data: JSON.stringify({
            user: user
        }),
        success: function (result) {

        },
        error: function (jqXHR, textStatus, errorThrown) {

             console.log(errorThrown)
        }
    }).done(function () {
    });
}

homeController.cs
C#
public ActionResult Index()
{

        if (!string.IsNullOrEmpty(SessionManager.Get<string>("SystemAuthToken") as string))
        {
            string userID = string.Empty;
            string serverSession = string.Empty;
            string clientSession = string.Empty;

              clientSession = BaseCore.Decrypt(Session["SystemAuthToken"].ToString(), true);
            userID = SessionManager.Get<string>("USER_ID");
            serverSession = new SettingBL().GetSession(int.Parse(userID));

            SessionManager.Save<string>("USER_ID", userID);

            if (serverSession.Equals(clientSession))
            {
                return View();
            }
            else
            {
                return RedirectToAction("Index", "Login");
            }

        }
        else
        {
            bool cookie = new SettingController().CheckRememberMeCookie(this.HttpContext);

            if (cookie)
                return View();
            else
                return RedirectToAction("Index", "Login");
        }

}

RouteConfig.cs
C#
  public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.MapRoute(
            "Default",
            "{controller}/{action}/{id}",
            new { controller = "Login", action = "Index", id = UrlParameter.Optional },
            new string[] { "Project.Controllers" }
        );
    }
}


What I have tried:

login.js file json.parse error
error: function (jqXHR, textStatus, errorThrown) {
        errorThrown >     <pre>'<', "<!DOCTYPE "... is not valid JSON

       }

if I do F5 after the error, it opens the home page
Posted
Updated 28-Jan-24 5:18am
v2
Comments
Graeme_Grant 28-Jan-24 5:24am    
That's a response page from the server. You need to read it as it will tell you why. IT usually means that your url is not correct.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900