繁体   English   中英

ASP.NET中的安全Cookie未添加安全标志

[英]Secure Cookies in ASP.NET not adding a secure Flag

我创建了一个asp.net项目,创建了一个新的HTTPCookie,我想在连接安全时向其添加安全标志。

var responseCookie = new HttpCookie(Test)
        {
            HttpOnly = true,
            Value = asdasdhoi234
        };
        if (FormsAuthentication.RequireSSL && Request.IsSecureConnection)
        {
            responseCookie.Secure = true;
        }
       Response.Cookies.Set(Test);

但是cookie仍然不安全,我不了解问题。

在我的httpsHeaders中,它仍然不显示我的安全cookie。我的域名是https,但我的cookie仍然不安全。

在此处输入图片说明

new HttpCookie 构造函数将字符串作为参数。 因此,我想您的Test是一个字符串。 您需要在实际的cookie对象而不是字符串上设置Secure标志。 尝试这个:

var responseCookie = new HttpCookie(Test)
{
    HttpOnly = true,
    Value = "asdasdhoi234",
    Secure = FormsAuthentication.RequireSSL && Request.IsSecureConnection
};
Response.Cookies.Set(responseCookie);

此外,请确保您的web.config包含requireSSL属性设置为true,如docs中所述

 <authentication mode="Forms"> <forms loginUrl="member_login.aspx" cookieless="UseCookies" requireSSL="true" path="/MyApplication" /> </authentication> 

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM