CORS is not working properly in none of various configurations.
I have two applications:
-
WebAPI in .NET Core 2.0
-
Frontend MVC in .NET Core 2.0 which uses javascript to send post requests.
For some reasons Firefox only "accepts" first request and the rest is denied due to CORS problems, meanwhile Chrome is more to be 50/50 - some request go thru and return data from backend properly, but some are blocked.
Additionally everything's inside virtualmachine with 2x port forward and 2x reverse proxy
Backend
Host: HOST_IP:55555 is forwarded to GUESTIP:80
Frontend
Host: HOST_IP:44444 is forwarded to GUESTIP:44445
And then inside vm nginx proxies
port 80 to: http://localhost:55659 (backend app)
port 22222 to http://localhost:63382 (frontend app)
Frontend is properly rendered in browser, backend is reachable by postman and returns data correctly and sometimes requests works in chrome.
POST http://10.1.14.142:55555/test/test 400 (Bad Request)
vue-resource.js:1088 POST http://10.1.14.142:55555/test/test 400 (Bad Request)
:55555/test/test:1 POST http://10.1.14.142:55555/test/test 503 (Service Temporarily Unavailable)
test:1 Failed to load http://10.1.14.142:55555//test/test: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://10.1.14.142:44444' is therefore not allowed access. The response had HTTP status code 503.
Cross-Origin Read Blocking (CORB) blocked cross-origin response http://10.1.14.142:55555//test/test with MIME type text/html. See https://www.chromestatus.com/feature/5629709824032768 for more details.
vue-resource.js:1088 POST http://10.1.14.142:55555//test/test 400 (Bad Request)
As you see some request reached backend and returned BadRequest due to sending empty form
Here's everything that I've been trying:
public void ConfigureServices(IServiceCollection services)
{
services.AddCors(options => options.AddPolicy("AllowAll",
p => p.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()));
jwt...
services
.AddMvc()
.AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining<Startup>());
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, Persistance.AppContext context)
{
app.UseDeveloperExceptionPage();
app.UseAuthentication();
app.UseCors("AllowAll");
app.UseMvc();
}
public void ConfigureServices(IServiceCollection services)
{
services.AddCors();
jwt...
services
.AddMvc()
.AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining<Startup>());
}
with:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, Persistance.AppContext context)
{
app.UseDeveloperExceptionPage();
app.UseAuthentication();
app.UseCors(builder => builder
.WithOrigins("http://10.1.14.142:44444"));
app.UseMvc();
}
or
public void Configure(IApplicationBuilder app, IHostingEnvironment env, Persistance.AppContext context)
{
app.UseDeveloperExceptionPage();
app.UseAuthentication();
app.UseCors(builder => builder
.WithOrigins("http://10.1.14.142:44444")
.AllowAnyHeader()
.AllowAnyMethod());
app.UseMvc();
}
or
public void Configure(IApplicationBuilder app, IHostingEnvironment env, Persistance.AppContext context)
{
app.UseDeveloperExceptionPage();
app.UseAuthentication();
app.UseCors(builder => builder
.WithOrigins("http://10.1.14.142:44444")
.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod());
app.UseMvc();
}
<ItemGroup>
<PackageReference Include="FluentValidation.AspNetCore" Version="7.6.104" />
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.9" />
<PackageReference Include="Microsoft.AspNetCore.HttpOverrides" Version="2.1.1" />
</ItemGroup>
Any ideas what it can be? Thanks in advance.
solution:
disabling nginx limiter...