【问题标题】:XMLHttpRequest cannot load due to access control checks由于访问控制检查,XMLHttpRequest 无法加载
【发布时间】:2021-08-05 14:26:30
【问题描述】:

打开显示 youtube 视频的页面时,我在不同的浏览器中遇到很多错误。
我查看了该主题,结果发现它与“Cros”有关,我尝试按照步骤启用该主题,但没有运气, 这是我在 startup.cs 中所做的,我使用的是 .net core 5

        public void ConfigureServices(IServiceCollection services)
    {
   
        services.AddHsts(options =>
        {

        });


        services.AddDbContextPool<ApplicationDBContext>(options =>
                           options.UseSqlServer(
                               Configuration.GetConnectionString("DefaultConnection")
       ));

        services.AddIdentity<ApplicationUserModel, IdentityRole>(options =>
        {


        }).AddEntityFrameworkStores<ApplicationDBContext>()
          .AddDefaultTokenProviders();


        services.AddCors(options =>
        {
            options.AddDefaultPolicy(builder =>
            {
                builder.AllowAnyOrigin().
                        AllowAnyMethod().
                        AllowAnyHeader();
            });
        });

        services.AddControllersWithViews();
        services.Configure<ForwardedHeadersOptions>(options =>
        {
            options.KnownProxies.Add(IPAddress.Parse("10.0.0.100"));
        });

    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        app.UseForwardedHeaders(new ForwardedHeadersOptions
        {
            ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
        });

        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
         }
        else
        {
            app.UseExceptionHandler("/Home/Error");
            app.UseHsts();
        }


        app.UseHttpsRedirection();

        app.UseStaticFiles();
        app.UseRouting();

        app.UseCors();

        app.UseAuthentication();
        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
       {
           endpoints.MapControllerRoute(
       name: "default",
       pattern: "{controller=Home}/{action=Index}/{id?}");
       });


    }
}

这是我在 safari 中遇到的错误。 任何帮助表示赞赏。

【问题讨论】:

  • 乍一看,这看起来像是 Safari 正在阻止内容。
  • CORS 不会是这里的问题。您是在运行广告拦截器,还是有内容安全策略 (CSP)?

标签: .net asp.net-mvc asp.net-core


【解决方案1】:

问题不在于您的代码。 除非您使用嵌入的 url,否则您无法在您的网站中打开 youtube。

1- 点击分享 see image

2- 点击嵌入并复制代码 see image.

【讨论】:

    猜你喜欢
    • 2018-05-29
    • 2018-11-12
    • 2020-10-28
    • 1970-01-01
    • 2020-12-18
    • 1970-01-01
    • 2020-10-18
    • 2017-09-16
    • 2018-03-07
    相关资源
    最近更新 更多