Успех Ajax не срабатывает - PullRequest
       27

Успех Ajax не срабатывает

0 голосов
/ 26 сентября 2019

Выполнение аутентификации Okta на веб-формах. Вход в систему работает, но часть перенаправления не

Я пытался с помощью void и вернуть объект / строку json, но не работает

, если я удаляю contentType и dataType из ajaxМетод, событие успеха работает, но тогда я не могу отладить метод, и он не делает то, что предполагалось сделать

Моя цель в конце веб-метода перенаправить на SignedIn.aspx, пробованный с этим кодомно не смог заставить его работать, поэтому я делаю на стороне клиента метод успеха ajax

     HttpContext.Current.Response.Redirect("SignedIn.aspx");

Ajax:

function FormSubmit() {
    $.ajax({
        type: "POST",
        url: "Example.aspx/Login",
        data: "{hiddenSessionTokenField:'" + $('#hiddenSessionTokenField').val() + "'}",
        dataType: "json",
        async:false,
        contentType: "application/json; charset=utf-8",
        success: function (response) {
            alert("Method Called Sucessfully" + response);
            window.location.href = "http://localhost:8080/SignedIn.aspx";
        },
        error: function (response) {
            alert("error " + response);
        }
    });
}

WebMethod

    [WebMethod(EnableSession = true)]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public static void Login(string hiddenSessionTokenField)
        {

        //var result = new { url = "http://localhost:8080/SignedIn.aspx" };

        if (!HttpContext.Current.User.Identity.IsAuthenticated)
        {
            var properties = new AuthenticationProperties();
            properties.Dictionary.Add("sessionToken", hiddenSessionTokenField);
            properties.RedirectUri = "~/SignedIn.aspx";

            //Okta Authentication
            HttpContext.Current.GetOwinContext().Authentication.Challenge(properties,
                OpenIdConnectAuthenticationDefaults.AuthenticationType);


            //System.Web.Script.Serialization.JavaScriptSerializer s = new System.Web.Script.Serialization.JavaScriptSerializer();

            //return s.Serialize(result));

        }
            //return s.Serialize(result));

    }

1 Ответ

0 голосов
/ 26 сентября 2019
$('#test').on('click', function () {
    $.ajax({
      type: "POST",
      url: "TEST.aspx/Login",
      data: "{hiddenSessionTokenField:'" + $('#hiddenSessionTokenField').val() + "'}",
      dataType: "json",
      contentType: "application/json; charset=utf-8",
      success: function (response) {
    //    alert("Method Called Sucessfully");
      window.location.href = "http://localhost:8080/index.aspx";
   },
    error: function (response) {
      alert("error " + response);
       }
      });
     })


    public static void Login(string hiddenSessionTokenField) {
        int x = 0;

    }
...