The Same Origin Policy disallows reading the remote resource

大兔子大兔子 提交于 2021-02-18 08:07:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!