【发布时间】:2020-10-13 09:25:52
【问题描述】:
我试图从 ajax 调用 mvc 核心操作方法,但在控制台中出现错误:
以下是代码: `
$.ajax({
url: LogOutUrl,
type: "POST",
dataType: "html",
contentType: "application/json; charset=utf-8",
success: function (data) {
if (data.status == "Success") {
alert("Done");
if (window.location.href.indexOf(EserviceLogOutUrl) === -1) {
window.location.href = EserviceLogOutUrl;
}
} else {
alert("Error occurs on the Database level!");
}
},
error: function () {
alert("An error has occured!!!");
}
});
MVC:
MVC:控制器:
public ActionResult Signout()
{
foreach (var cookie in Request.Cookies.Keys)
{
Response.Cookies.Delete(cookie);
}
_httpContextAccessor.HttpContext.Session.Clear();
return new RedirectResult("http://Google.com");//Redirecting to different website in antoher domain.
}
控制台错误:我能够调用操作方法。但无法重定向 URL。
SEC7123:请求标头 x-requested-with 不在 Access-Control-Allow-Headers 列表中。
【问题讨论】:
标签: ajax asp.net-mvc model-view-controller