【问题标题】:How can I not secure one cookies in Asp.Net if Web.Config secure all cookies?如果 Web.Config 保护所有 cookie,我怎么能不保护 Asp.Net 中的一个 cookie?
【发布时间】:2020-08-13 13:42:07
【问题描述】:

如果 Web.config 有此设置:

<httpCookies httpOnlyCookies="true" requireSSL="true" />

现在所有的 cookie 都带有 Secure 和 HttpOnly 标志,但是如果我确实需要一个不安全的 cookie 以便我可以将某些内容传递给客户端,以便其 javascript 读取其中的数据,该怎么办?如何使这个 cookie 不带有 Secure 和 HttpOnly 标志?

我需要这些数据可用于任何页面,除了 cookie 之外还有其他方法吗?

谢谢,

【问题讨论】:

    标签: asp.net security cookies


    【解决方案1】:

    事实证明,您代码中的设置取代了 Web.Config 中的设置。只有没有使用 Secure 和 HttpOnly 指定的 cookie 才会受到 Web.Config 中的设置的影响。

    示例代码:

    filterContext.HttpContext.Response.Cookies.Add(new HttpCookie("mycookie", "mycookievalue") {
                    Secure = false,HttpOnly = false
                });
    

    因此,无论 Web.Config 中的设置是什么,“mycookie”都不会受到保护

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-19
      • 2017-12-01
      • 2013-07-04
      • 1970-01-01
      • 2019-02-10
      • 2011-08-24
      • 2021-05-07
      • 2012-05-03
      相关资源
      最近更新 更多