通过 Set-Cookie 设置 cookie 的尝试被阻止,因为它具有 "Secure" 属性

This attempt to set a cookie via a Set-Cookie was blocked because it had the "Secure" attribute

我在 IIS 10 上部署了一个 ASP.NET webforms/mvc 混合应用程序。我有这个应用程序的两个绑定,一个只有 localhost:portNo 绑定,另一个有 DNSDomainName:portNo捆绑。两者都是 Http 绑定。 SSL 已关闭。我收到错误

“此尝试通过 Set-Cookie 设置 cookie 已被阻止,因为它具有“安全”属性但未通过安全连接接收。”

当我测试 DNSDomainName:portNo 绑定时(设置会话失败)。 localhost:portNo 绑定没有任何问题。为什么会这样?我该如何解决这个问题?

您的 cookie 配置为需要 HTTPS 连接。当您尝试在非安全连接上设置它们时,它们将被拒绝。

检查您的 web.config 文件设置:

<httpCookies requireSSL="true" />

将该设置更改为 false,您的会话 cookie 应该开始工作。

注意: 一旦您发布了您的网站,它应该只通过 HTTPS 提供服务,并且此设置应该改回 true.

Secure Cookie Attribute | OWASP Foundation

localhost 绑定之所以有效,是因为大多数浏览器都有特殊代码将与该主机名的连接视为“安全”,即使它们不使用 HTTPS。

Locally-delivered resources such as those with http://127.0.0.1 URLs, http://localhost and http://*.localhost URLs (e.g. http://dev.whatever.localhost/), and file:// URLs are also considered to have been delivered securely.
Secure contexts - Web security | MDN