【发布时间】:2025-12-08 16:45:01
【问题描述】:
在 WebForms 上进行 Okta 身份验证 登录有效,但重定向部分无效
我尝试使用 void 并返回 json 对象/字符串,但不起作用
如果我从 ajax 方法中删除 contentType 和 dataType,成功事件会起作用,但是我无法调试该方法,并且它没有做预期做的事情
我的目标是在 webmethod 的末尾重定向到 SignedIn.aspx 尝试使用此代码但无法使其工作,这就是我通过 ajax 成功方法做客户端的原因
HttpContext.Current.Response.Redirect("SignedIn.aspx");
阿贾克斯:
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(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