问题
I am getting a problem with possibly Cors. I am doing local dev(react frontend, asp.net core 2 api backend).
Both IE 11 and Chrome have no problem, but Firefox has a problem with my requests.
I just keep getting "Network Error" from my calls.
I disabled "HSTS" in firefox and now I am seeing a "warning message"
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://localhost:44391/api/tokens/auth. (Reason: CORS request did not succeed).
In my cor right now to make dev simple I just have
public void ConfigureServices(IServiceCollection services)
{
services.AddCors();
...
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseCors(builder => builder
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials());
}
回答1:
I had the same issue, but it turned out that the CORS error was a bit of a red herring. I opened the Developer Console in Firefox, clicked on the Options request under Network and then went to the security tab. I saw the following:
An error occurred mozilla_pkix_error_self_signed_cert
I fixed this by going to the Properties for my .Net Core app in Visual Studio. I selected Debug from the menu on the left hand side. There was a checkbox on the page called Enable SSL along with a URL (https://localhost:44358/ in my case). I browsed to this page in Firefox, got a warning page, added a security exception for it and everything worked as expected after that.
If you don't see the warning page clear your cache as per the suggestions here: Certificate Issue
来源:https://stackoverflow.com/questions/51428883/the-same-origin-policy-disallows-reading-the-remote-resource