【发布时间】:2022-01-24 04:46:15
【问题描述】:
在我的 Asp.net Core WebApi 中,我已经在 Startup.cs 文件中配置了 Configure 方法,如下所示:
app.UseCors(option=>
option.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod());
但是当我尝试将数据发布到 Action 方法时(使用 axios)。出现以下错误:
Access to XMLHttpRequest at 'my domain' from origin 'my domain' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
我该如何解决这个错误?
【问题讨论】:
标签: asp.net-core-mvc asp.net-core-webapi asp.net-core-5.0