简体   繁体   English

ASP.Net Core Web Api access-control-max-age 未在响应中发送 header

[英]ASP.Net Core Web Api access-control-max-age not being sent in the response header

I have the SetPreFlightMaxAge in the Startup.cs.我在 Startup.cs 中有 SetPreFlightMaxAge。 But the chrome Inspect > Network tab doesn't show it in the Response Headers.但 chrome Inspect > Network 选项卡未在响应标头中显示。

Startup.cs启动.cs

app.UseCors(o =>
{
o.WithOrigins(allowedDomains.ToArray())
.SetPreFlightMaxAge(TimeSpan.FromMinutes(10))
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials()
});

Response Headers (GET method): In addition to some other headers it sends these headers.响应标头(GET 方法):除了一些其他标头之外,它还发送这些标头。 There is a max-age in the third line below, but that's not the 10 mins value set in the Startup.cs下面第三行有一个 max-age,但这不是 Startup.cs 中设置的 10 分钟值

access-control-allow-credentials: true
access-control-allow-origin: ...
set-cookie: ...
strict-transport-security: max-age=2592000
vary: Origin,Accept-Encoding

Response Headers (OPTIONS method):响应标头(OPTIONS 方法):

access-control-allow-credentials: true
access-control-allow-headers: ...
access-control-allow-origin: ...
set-cookie: ...

In .NET core 3.1 try adding it in ConfigureServices在 .NET 核心 3.1 中尝试将其添加到 ConfigureServices

services.AddCors(o => o.AddPolicy("xyzpolicy", builder =>
            {
  
                builder.AllowAnyOrigin()
                       .AllowAnyMethod()
                       .AllowAnyHeader()
                       .SetPreflightMaxAge(TimeSpan.FromMinutes(10));
            }));

They say its caped to 2 hours for Chromium-based browsers他们说基于 Chromium 的浏览器最多需要 2 小时

暂无
暂无

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

相关问题 不存在“Access-Control-Allow-Origin”标头 - 面向 .net 框架 4.5.1 的 asp.net 核心 Web api - No 'Access-Control-Allow-Origin' header is present - asp.net core web api targeting .net framework 4.5.1 预检响应中的 Access-Control-Allow-Headers 不允许 ASP.Net WEB API 请求标头字段授权 - ASP.Net WEB API Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response 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? ASP.NET Core Web API + Angular 对预检请求的响应未通过访问控制检查:预检请求不允许重定向 - ASP.NET Core Web API + Angular Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request 如何将自定义标头添加到 ASP.NET Core Web API 响应 - How to add custom header to ASP.NET Core Web API response Angular 4 / Asp.net Web API-不存在“ Access-Control-Allow-Origin”标头 - Angular 4 / Asp.net Web API - No 'Access-Control-Allow-Origin' header is present Access-Control-Allow-Origin 在标头请求 ASP.NET Web API 上出现两次 - Access-Control-Allow-Origin appearing twice on header request ASP.NET Web API Swagger UI 响应示例 Asp.Net Core Web Api - Swagger UI Response Example Asp.Net Core Web Api 流利验证自定义响应 ASP.NET 核心 Web API - Fluent validation custom response ASP.NET Core Web API ASP.NET Core Web API身份验证允许未经授权的访问 - ASP.NET Core Web API Authentication allowing unauthorized access
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM