Access to XMLHttpRequest at 'http://localhost:60540/api/Orders' from origin 'http://localhost:63343' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
一般来说前后端分离都会遇到跨域问题,WebApi也不例外咯,然后今天做作业的时候遇到了
在百度上找了一番,都是老版本的解决方案,没有我使用的这个webapi5,文件结构是这样的。

最后还是去翻官方文档找到了解决方案。

public void ConfigureServices(IServiceCollection services)
{
services.AddCors(options =>
{
options.AddPolicy(MyAllowSpecificOrigins,
builder =>
{
builder.WithOrigins("http://example.com",
"http://www.contoso.com")
.AllowAnyHeader()
.AllowAnyMethod();
});
});
services.AddControllers();
}https://docs.microsoft.com/zh-cn/aspnet/core/security/cors?view=aspnetcore-5.0#cors-with-named-policy-and-middleware
还有职教云zhushou的源码吗,我最近在学python,想看看,谢谢了
噢 不用了 你上传了github