【发布时间】:2017-09-07 10:42:57
【问题描述】:
我有一个包含多个 .net 核心项目的项目。我在从项目 A 向项目 B 拨打电话时遇到问题。我不断收到一个 cors 问题,指出存在 no-access-control-allow-origin。我在下面有这个设置,由于某种原因无法正常工作。
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddCors();
services.AddMvc().AddMvcOptions(options => options.RespectBrowserAcceptHeader = true);
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IAntiforgery antiforgery)
{
loggerFactory.AddDebug(LogLevel.Information).AddSerilog();
app.UseCors(builder =>
builder.WithOrigins("*")
.WithMethods("*")
.AllowAnyHeader()
.AllowAnyMethod()
.AllowAnyOrigin()
);
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
【问题讨论】:
标签: c# .net asp.net-core cors