//跨域配置
//----在Startup类里面
public void ConfigureServices(IServiceCollection services)
{
//跨域配置
services.AddCors(options =>
{
// Policy 名稱 CorsPolicy 是自訂的,可以自己改
options.AddPolicy("MyCors", policy =>
{
// 設定允許跨域的來源,有多個的話可以用 `,` 隔開
policy.WithOrigins("https://localhost:44387/", "https://localhost:44342")
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials();
});
});
services.AddControllers();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseCors("MyCors");
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}