c# - CORS 的 ASP.NET Web API 和 IdentityServer 问题
问题描述
我有一个 MVC 控制器正在注销,它工作正常。我们决定从 MVC 迁移到 Web API 并翻译所有代码。现在,在注销操作时,我收到响应错误,例如
对路径的 CORS 请求:路径到我的身份服务器/从源登录:localhost:port但由于 CORS 路径无效而被拒绝。
这让我很困惑,因为在 IS 上启用了 CORS,如下所示
factory.CorsPolicyService =
new Registration<ICorsPolicyService>(
new DefaultCorsPolicyService
{
AllowAll = true
});
这里是API 控制器 中注销操作的实现
[HttpGet]
[Route("logout")]
public void Logout()
{
HttpContext.Current
.GetOwinContext()
.Authentication
.SignOut(new AuthenticationProperties
{
RedirectUri = Properties.Settings.Default.SelfUrl,
});
}
这里是 MVC 控制器
[HttpGet]
public ActionResult Logout()
{
HttpContext.GetOwinContext().Authentication.SignOut(
new AuthenticationProperties()
{
RedirectUri = Properties.Settings.Default.SelfUrl,
});
return RedirectToAction("Index");
}
我用谷歌搜索了很多,但没有办法找到原因。任何帮助