简体   繁体   English

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

[英]Access httponly cookie from server side (ASP.NET 4.5)

I am trying to retrieve an httponly cookie over https from code behind and then set to session variable to retrieve from web form page. 我试图从后面的代码中通过https检索httponly cookie,然后设置为session变量以从Web表单页面中检索。 The code is on the same domain. 该代码在同一域中。

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

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

In my web form, I try to retrieve the session variable, but value is null. 在我的Web表单中,我尝试检索会话变量,但值为null。

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

Instead of 代替

Session.Add("TestCookie", cookie);

I think you mean to write 我想你是要写

Session.Add("TestCookie", token_value);

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

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