简体   繁体   中英

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. 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.

<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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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