mic*_*cer 4 c# asp.net-web-api asp.net-core asp.net-core-2.2
在我的中appsettings.json我添加了这行代码:
"Hsts": {
"HstsEnable": true
}
Run Code Online (Sandbox Code Playgroud)
在launchSettings.json我添加https://localhost:5000:
"applicationUrl": "http://localhost:5001;https://localhost:5000"
Run Code Online (Sandbox Code Playgroud)
然后,Program.cs我使用了这个网址:
return WebHost.CreateDefaultBuilder(args)
.UseKestrel(x => x.AddServerHeader = false)
.UseUrls("http://localhost:5001", "https://localhost:5000")
.UseStartup<Startup>()
Run Code Online (Sandbox Code Playgroud)
在启动类中,在Configure方法中我Hsts从以下位置获取值appSettings.json:
if (Configuration.GetSection("Hsts").GetValue<bool>("HstsEnable"))
{
app.UseHsts();
}
app.UseHttpsRedirection();
Run Code Online (Sandbox Code Playgroud)
经过所有这些步骤我无法得到Strict-Transport-Security。我从响应标头中得到的所有内容是:
cache-control: no-store,no-cache
content-type: application/json; charset=utf-8
pragma: no-cache
Run Code Online (Sandbox Code Playgroud)
从响应中截取的标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
Run Code Online (Sandbox Code Playgroud)
所以这件事有些不对劲Hsts。
如何HSTS在我上面提到的响应标头中添加标头?我需要将标头硬编码到我的Configure方法中吗?
context.Response.Headers.Add("Strict-Transport-Security", "max-age=31536000");
Run Code Online (Sandbox Code Playgroud)
UseHsts排除以下环回主机:
localhost :IPv4 环回地址。
127.0.0.1 :IPv4 环回地址。
[::1] :IPv6 环回地址。
您可以尝试发布 Web 应用程序并检查标头Strict-Transport-Security。
| 归档时间: |
|
| 查看次数: |
10740 次 |
| 最近记录: |