Ajax成功事件不会触发

问题描述 投票:0回答:1

在WebForms上进行Okta身份验证登录有效,但重定向部分无效

我尝试使用void并返回json对象/字符串,但不起作用

如果我从ajax方法中删除contentType和dataType,则成功事件有效,但随后我无法对该方法进行调试,并且它没有按预期执行操作

我的目标是在重定向到SignedIn.aspx的Web方法的结尾,尝试使用此代码,但也无法使其正常工作,这就是为什么我通过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));

    }
javascript c# ajax webmethod okta
1个回答
0
投票
$('#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;

    }
© www.soinside.com 2019 - 2024. All rights reserved.