即使请求被视为CORS,即使它位于同一个域中的地址之间,但使用不同的协议?从http呼叫https时,Chrome抛出CORS错误,而ASP Core不发送CORS头
因为我在控制台中看到代码401:
XMLHttpRequest cannot load
https://xxx.yyy.com/appname/css/left-pane-menu.component.min.css.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://xxx.yyy.com' is therefore not allowed access.
The response had HTTP status code 401.
一方面,asp的核心将不会发送CORS标头为同一来源,对其他Chrome不会接受来自其他协议的请求。哇。
除了从相同的协议调用资源,我的选择是什么。 我不能那样做。我需要调用https,总是因为某些Azure Enterprise代理设置导致我的网站误认为在使用https调用时使用http调用,因此html中的基本url标记设置为http://xxx.yyy.com/myapp,Chrome会抛出它无法访问不安全来自安全连接的资源。
我Startup.cs看起来是这样的:
public void ConfigureServices(IServiceCollection services)
{
services.AddCors();
services.AddMvc()
.AddJsonOptions(x =>
{
x.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseCors(c=>
c
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials()
);
app.UseResponseCompression();
app.UseStaticFiles(new StaticFileOptions());
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
routes.MapSpaFallbackRoute("spa-fallback", new { controller = "Home", action = "Index" });
});
}
这是正确的行为。 Http/https被分类为不同的来源。您必须在您的申请中处理允许http和https都允许 – Tseng
但您的Cors也配置错误。你应该把CORS放在你的静态文件中间件之后(或者只限于js/json),因为甚至css都会通过CORS检查,你很可能不想这样做。同时发布您的CORS设置代码 – Tseng
您使用什么进行授权? –