同源策略禁止读取远程资源 [英] The Same Origin Policy disallows reading the remote resource
问题描述
我可能会遇到Cors问题.我正在做本地开发(反应前端,asp.net核心2 api后端).
I am getting a problem with possibly Cors. I am doing local dev(react frontend, asp.net core 2 api backend).
IE 11和Chrome都没有问题,但是Firefox的请求有问题.
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.
我在firefox中禁用了"HSTS",现在我看到的是警告消息"
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).
现在在我的cor中,使开发人员变得简单
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());
}
推荐答案
我遇到了同样的问题,但事实证明,CORS错误有点像是鲱鱼.我在Firefox中打开了开发者控制台,单击网络"下的选项"请求,然后转到安全性"选项卡.我看到了以下内容:
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:
发生错误mozilla_pkix_error_self_signed_cert
An error occurred mozilla_pkix_error_self_signed_cert
我通过在Visual Studio中转到.Net Core应用程序的属性"来解决此问题.我从左侧菜单中选择调试".在我的情况下,页面上有一个名为Enable SSL以及URL的复选框( https://localhost:44358/).我在Firefox中浏览到此页面,看到警告页面,并为其添加了安全例外,之后一切正常.
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
这篇关于同源策略禁止读取远程资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!