简体   繁体   English

ASP .NET 核心中 CORS 中的问题 - 响应中的“访问控制允许来源”header 的值不能是通配符 '*

[英]Issue in CORS in ASP .NET Core - The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*

I'm getting the below error我收到以下错误

Access to XMLHttpRequest at ' http://localhost:5000/api/values/track/?name=name&time=1589425390870 ' from origin ' http://localhost:23456 ' has been blocked by CORS policy: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Access to XMLHttpRequest at ' http://localhost:5000/api/values/track/?name=name&time=1589425390870 ' from origin ' http://localhost:23456 ' has been blocked by CORS policy: The value of the 'Access -Control-Allow-Origin' 当请求的凭据模式为“包含”时,响应中的 header 不能是通配符“*”。 The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute. XMLHttpRequest 发起的请求的凭证模式由 withCredentials 属性控制。

I have configured Asp.net core app like below我已经配置了 Asp.net 核心应用程序,如下所示

public void ConfigureServices(IServiceCollection services)
        {

            services.AddCors(o => o.AddPolicy("MyPolicy", builder =>
            {
                builder.AllowAnyOrigin()
                       .AllowAnyMethod()
                       .AllowAnyHeader().AllowCredentials() ;
            }));


            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseCors("MyPolicy");
            app.UseMvc();
        }

Content type: application/x-www-form-urlencoded内容类型:application/x-www-form-urlencoded

Can some one please help me in resolving this issue?有人可以帮我解决这个问题吗?

The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'.当请求的凭证模式为“包含”时,响应中的“Access-Control-Allow-Origin”header 的值不能是通配符“*”。

As error indicates that you configure your app with both AllowAnyOrigin and AllowCredentials methods, which cause that the CORS service returns an invalid CORS response.由于错误表明您使用AllowAnyOriginAllowCredentials方法配置您的应用程序,这会导致 CORS 服务返回无效的 CORS 响应。

You can modify the code to enable specific origins, like below.您可以修改代码以启用特定来源,如下所示。

builder.WithOrigins("set_specified_origins_here")
        .AllowAnyMethod()
        .AllowAnyHeader()
        .AllowCredentials();

For detailed information about "Set the allowed origins", please check following doc: https://docs.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-2.0#set-the-allowed-origins-1有关“设置允许的来源”的详细信息,请查看以下文档: https://docs.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-2.0#set-the-allowed-起源-1

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当请求的凭据模式为“include”时,响应中的“Access-Control-Allow-Origin”标头的值不能是通配符“*” - The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include' ASP.NET Core CORS WebAPI:没有 Access-Control-Allow-Origin 标头 - ASP.NET Core CORS WebAPI: no Access-Control-Allow-Origin header CORS asp.net 核心 webapi - 缺少 Access-Control-Allow-Origin 标头 - CORS asp.net core webapi - missing Access-Control-Allow-Origin header ASP.NET Core CORS WebAPI:不保留 Access-Control-Allow-Origin 标头 - ASP.NET Core CORS WebAPI: persist no Access-Control-Allow-Origin header ASP.NET Core Web Api发送Access-Control-Allow-Origin:null CORS头和chrome是错误的,如何修复? - ASP.NET Core Web Api sending Access-Control-Allow-Origin: null CORS header and chrome is erroring, how to fix? 在Access-Control-Allow-Origin标头中找不到源[域]。 ASP .NET CORE API MVC - Origin [domain] not found in Access-Control-Allow-Origin header. ASP .net CORE API mvc ASP.NET Core 6 中的“访问控制允许来源” - 'Access-Control-Allow-Origin' in ASP.NET Core 6 ASP.NET 5: Access-Control-Allow-Origin 响应 - ASP.NET 5: Access-Control-Allow-Origin in response React+ASP.NET.Core:请求的资源上不存在“Access-Control-Allow-Origin”标头 - React+ASP.NET.Core : No 'Access-Control-Allow-Origin' header is present on the requested resource 在Asp.net Core 2.1的Angular 6中不存在“ Access-Control-Allow-Origin”标头 - No 'Access-Control-Allow-Origin' header is present Angular 6 with Asp.net Core 2.1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM