Javascript Ajax成功事件不会发生';t火
在WebForms上执行Okta身份验证 登录有效,但重定向部分无效 我尝试使用void并返回json对象/字符串,但不起作用 如果我从ajax方法中删除contentType和dataType,则成功事件会起作用,但我无法消除该方法的bug,并且它没有执行预期的操作 我的目标是在webmethod的末尾重定向到SignedIn.aspx。我用这段代码尝试过,但也无法使它工作,这就是为什么我通过ajax成功方法在客户端工作的原因Javascript Ajax成功事件不会发生';t火,javascript,c#,ajax,webmethod,okta,Javascript,C#,Ajax,Webmethod,Okta,在WebForms上执行Okta身份验证 登录有效,但重定向部分无效 我尝试使用void并返回json对象/字符串,但不起作用 如果我从ajax方法中删除contentType和dataType,则成功事件会起作用,但我无法消除该方法的bug,并且它没有执行预期的操作 我的目标是在webmethod的末尾重定向到SignedIn.aspx。我用这段代码尝试过,但也无法使它工作,这就是为什么我通过ajax成功方法在客户端工作的原因 HttpContext.Current.Response
HttpContext.Current.Response.Redirect("SignedIn.aspx");
阿贾克斯:
网络方法
[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));
}
就像我说的,我更具体地尝试了这个HttpContext.Current.Response.Redirect(“SignedIn.aspx”);因为这个方法是静态的,所以我不得不添加HttpContext.Current,但它没有做任何事情不确定它是否是一个输入错误,但它需要是Response.Redirect(“~/SignedIn.aspx”);我确实用“~/SignedIn.aspx”试过了,但正如我所说的,它不起作用。用一个适合我的示例编辑我的答案。我需要一个静态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));
}
$('#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;
}