C# ASP.NET核心响应头中没有HSTS头

C# ASP.NET核心响应头中没有HSTS头,c#,asp.net-core,asp.net-web-api,asp.net-core-2.2,C#,Asp.net Core,Asp.net Web Api,Asp.net Core 2.2,在我的appsettings.json中,我添加了以下代码行: "Hsts": { "HstsEnable": true } 在launchSettings.json中我添加了https://localhost:5000: "applicationUrl": "http://localhost:5001;https://localhost:5000" 然后,在Program.cs中,我使用了以下URL: return WebHost.CreateDefaultBuilder(ar

在我的
appsettings.json
中,我添加了以下代码行:

"Hsts": {
    "HstsEnable": true
 }
launchSettings.json中我添加了
https://localhost:5000

"applicationUrl": "http://localhost:5001;https://localhost:5000"
然后,在
Program.cs
中,我使用了以下URL:

 return WebHost.CreateDefaultBuilder(args)
            .UseKestrel(x => x.AddServerHeader = false)
            .UseUrls("http://localhost:5001", "https://localhost:5000")
            .UseStartup<Startup>()
经过所有这些步骤后,我无法获得严格的运输安全。我从响应标题中获得的信息包括:

 cache-control: no-store,no-cache 
 content-type: application/json; charset=utf-8 
 pragma: no-cache 
Hsts
从响应中剪切标题。没有所有这些代码行(在我的应用程序中设置
hsts
),我会得到以下响应标题:

access-control-allow-credentials: true 
access-control-allow-origin: * 
access-control-expose-headers: Content-Disposition 
cache-control: no-store,no-cache 
content-type: application/json; charset=utf-8 
date: Fri, 11 Oct 2019 09:21:30 GMT 
pragma: no-cache 
transfer-encoding: chunked 
vary: Origin 
x-frame-options: DENY 
x-stackifyid: id
因此,此
Hsts
有问题

如何在我上面提到的响应头中添加
HSTS
头?是否需要将头硬编码到我的
Configure
方法

context.Response.Headers.Add("Strict-Transport-Security", "max-age=31536000");

从官方文件

UseHsts
排除以下环回主机:

  • localhost:IPv4环回地址

  • 127.0.0.1:IPv4环回地址

  • [::1]:IPv6环回地址


您可以尝试发布web应用程序,并检查标题严格的传输安全性

您用于测试此应用程序的请求的URL是什么?@KirkLarkin
http://localhost:5001/
HSTS中间件不会为环回地址上的请求添加HSTS头。请参阅(该部分的末尾)。
context.Response.Headers.Add("Strict-Transport-Security", "max-age=31536000");