从服务器端访问httponly cookie(ASP.NET 4.5)

时间:2016-02-23 17:42:27

标签: c# asp.net cookies webforms httponly

我正在尝试从后面的代码中通过https检索httponly cookie,然后设置为会话变量以从Web表单页面检索。代码位于同一个域中。

HttpCookie cookie = Request.Cookies["CookieName"];
            if (cookie != null)
            {
                string token_value = cookie.Value.ToString();

                Session.Add("TestCookie", token_value);
            }

在我的网络表单中,我尝试检索会话变量,但值为null。

<script type="text/javascript">
        var cookie_value = '<%= Session["TestCookie"] %>';
        alert(cookie_value);
    </script>

1 个答案:

答案 0 :(得分:0)

而不是

Session.Add("TestCookie", cookie);

我认为你的意思是写

Session.Add("TestCookie", token_value);