[英]CORS issues after upgrading to .NET Core 2.2
I had an .NET Core 2.1 application which handled CORS well. 我有一个.NET Core 2.1应用程序,可以很好地处理CORS。 But after upgrading to 2.2 I faced the problem:
但是升级到2.2后,我遇到了问题:
Access to XMLHttpRequest at ' https://content.xxxx/user/avatar ' from origin ' https://cabinet.xxxx ' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
从起源' https://cabinet.xxxx '在' https://content.xxxx/user/avatar '处对XMLHttpRequest的访问已被CORS策略阻止:对预检请求的响应未通过访问控制检查:否'访问-Control-Allow-Origin'标头出现在请求的资源上。
Response Headers: (might this be an issue with IIS?) 响应标题:(这可能是IIS的问题吗?)
Connection: close
连接方式:关闭
Content-Length: 315
内容长度:315
Content-Type: text/html;
内容类型:text / html; charset=us-ascii
字符集= us-ascii
Date: Tue, 22 Jan 2019 15:08:26 GMT
日期:2019年1月22日星期二15:08:26 GMT
Server: Microsoft-HTTPAPI/2.0
伺服器:Microsoft-HTTPAPI / 2.0
I tried every combination I could find here (enabling CORS before and after MVC, adding and removing UseCors from Configure method), but nothing worked. 我尝试了在这里可以找到的每种组合(在MVC之前和之后启用CORS,从Configure方法中添加和删除UseCors),但是没有任何效果。
public IServiceProvider ConfigureServices(IServiceCollection services)
{
...
services.AddCors(options =>
{
options.AddPolicy("MyPolicy",
builder => builder.WithOrigins("https://cabinet.xxxxxx")
.AllowAnyMethod()
.AllowCredentials()
.AllowAnyHeader());
});
services.AddMvc();
...
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHsts();
//app.UseHttpsRedirection();
app.UseCors("MyPolicy");
app.UseMvc();
app.UseDefaultFiles();
app.UseStaticFiles();
}
and the method is 方法是
[HttpPost]
[EnableCors("MyPolicy")]
[Route("user/avatar")]
[Authorize]
public async Task Method(IFormFile file) {...}
Am I missing something? 我想念什么吗? I don't want to downgrade back to 2.1.
我不想降级到2.1。
Apparently there was an issue with IIS configuration. 显然,IIS配置存在问题。 Moving website to another port helped.
将网站移至另一个端口有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.