C# 基本API响应apnetnet core 3.0中缺少CORS标头
我刚刚用基本的天气预报API创建了一个默认的DotnetCore3.0API项目。我想在我对项目做任何其他事情之前让CORS工作 在启动中,我有以下代码C# 基本API响应apnetnet core 3.0中缺少CORS标头,c#,asp.net-core,cors,asp.net-core-webapi,asp.net-core-3.0,C#,Asp.net Core,Cors,Asp.net Core Webapi,Asp.net Core 3.0,我刚刚用基本的天气预报API创建了一个默认的DotnetCore3.0API项目。我想在我对项目做任何其他事情之前让CORS工作 在启动中,我有以下代码 private readonly string MyAllowSpecificOrigins = "_myAllowSpecificOrigins"; // This method gets called by the runtime. Use this method to add services to the container.
private readonly string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddCors(options =>
{
options.AddPolicy(MyAllowSpecificOrigins,
builder =>
{
builder.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod();
});
});
services.AddControllers();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseCors(MyAllowSpecificOrigins);
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
正如你所看到的,我没有做任何特别的或看似不正确的事情。这直接来自MSDN文档。。。。
问题是,当通过浏览器和邮递员发送请求时,给定的响应中没有预期的头
我已经用谷歌搜索出了这些废话,但什么也没有得到。我错过什么了吗?这可能是环境问题吗?它是否与旧版本的core有所不同?您是否可以显示您正在处理的请求的CURL版本sending@Roooss你解决问题了吗?与CORS不起作用相同的问题。Net Core 3.0它确实订购了IIRC