![](/img/trans.png)
[英]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'
[英]Issue in CORS in ASP .NET Core - The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*
我收到以下错误
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 不能是通配符“*”。 XMLHttpRequest 发起的请求的凭证模式由 withCredentials 属性控制。
我已经配置了 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();
}
内容类型:application/x-www-form-urlencoded
有人可以帮我解决这个问题吗?
当请求的凭证模式为“包含”时,响应中的“Access-Control-Allow-Origin”header 的值不能是通配符“*”。
由于错误表明您使用AllowAnyOrigin
和AllowCredentials
方法配置您的应用程序,这会导致 CORS 服务返回无效的 CORS 响应。
您可以修改代码以启用特定来源,如下所示。
builder.WithOrigins("set_specified_origins_here")
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials();
有关“设置允许的来源”的详细信息,请查看以下文档: 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.