I have a c# webapi application where the endpoint just redirects, however, when I call from an HTML page that has an AJAX call, it does not redirect, could you please help me where I'm missing? I tried all combinations.
[HttpPost]
[Route("Redirect")]
public async Task<IActionResult> Redirect()
{
var response = "https://google.com";
return Redirect(response);
}
AJAX call
$.ajax({
url: "https://10.10.45.2/api/Redirect",
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function(data, textStatus, xhr) {
window.location = xhr.location; // I know this is not correct
},
complete: function(xhr, textStatus) {
console.log("Complete: " + xhr.status);
},
error: function (jqXHR, timeout, message) {
console.log("Complete: " + jqXHR.status);
console.log("Response Location :" + loginPageRedirectHeader);
}
});