JavaScript的:读出从cookie的会话ID [英] Javascript: Read out session id from cookie

查看:519
本文介绍了JavaScript的:读出从cookie的会话ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关的WebSockets我必须从cookie暴露我的SessionID。

for websockets I have to expose my sessionid from the cookie.

我寻觅了一下,发现我应该能够访问的cookie:

I have searched a bit and found that I should be able to access cookies by:

console.log(document.cookie);

不幸的是,这并不工作,或者更好的document.cookie包含空字符串,甚至镀铬本身就说明了我的饼干也验证工作。

unfortunatly this doesn't work or better document.cookie contains an empty string even chrome itself shows me the cookie also authentication works.

也可以是铬隐藏的cookie对JavaScript?

Can it be that chrome hides the cookie for javascript?

推荐答案

如果该服务器配置为使用的仅Http 标志。通过这种方式,饼干变为不可见/不可访问的客户端脚本语言,如JS。

That can happen if the server is configured to send the session cookie with the HttpOnly flag. This way the cookie becomes invisible/inaccessible to client side scripting languages like JS.

要实现你的具体功能要求,无论是重新配置服务器不这样做,或者寻找替代方法,例如设置自定义的cookie(不包括仅Http 标志,当然),或让服务器端视图技术动态打印当前会话ID作为一个JS变量或为某些属性HTML元素,以便能够JS通过遍历HTML DOM访问它。

To achieve your concrete functional requirement, either reconfigure the server to not do so, or look for alternate means, e.g. setting a custom cookie (without the HttpOnly flag, of course), or letting the server side view technology dynamically print the current session ID as a JS variable or as an attribute of some HTML element so that JS can access it by traversing the HTML DOM.

这篇关于JavaScript的:读出从cookie的会话ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆