Express会话可以不使用cookie进行吗? [英] Can a Express session works without cookie?

查看:116
本文介绍了Express会话可以不使用cookie进行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

会话是服务器端对象,位于服务器上。每个会话都有一个会话ID。会话ID是唯一的数字,服务器在其访问(会话)期间将其分配给特定用户。默认情况下,会话ID会附加到cookie,并且该cookie将在其请求/响应期间从客户端到服务器(以及服务器到客户端)共享。服务器将根据从cookie中检索到的会话ID来识别会话。

The session is server side object and resides on the server. Every session will have a Session ID. A Session ID is a unique number, the server assigns to a specific user, during his visit(session). And by default, session ID is attached to a cookie and this cookie will be shared from client to server (and server to client) during its requests/responses. And the server will identify session based on a session ID which is retrieved from the cookie.

所以我想知道Express会话是否可以在无cookie的情况下工作?

So I want to know if a Express session works cookieless?

推荐答案


所以我想知道Express会话是否可以不使用cookie?

So I want to know if a Express session works cookieless?

否。实际的快速会话模块仅适用于cookie。它将会话ID存储在cookie中,以便来自该特定浏览器的下一个页面请求或Ajax请求将包含该cookie,express-session可以查找与该会话ID相对应的服务器端会话对象。

No. The actual express-session module only works with a cookie. It stores a session ID in the cookie so that the next page request or Ajax request that comes from that particular browser will contain that cookie and express-session can look up the appropriate server-side session object that corresponds to that session ID.

可以创建不使用cookie的会话系统。通常,可以通过将会话ID作为查询参数放在URL中来完成此操作,例如:

It is possible to create a session system that does not use a cookie. That is typically done by putting a session id in the URL as a query parameter as in:

http://somedomain.com/somepath?sessionID=0823408234

但是,除非您这样做,否则以这种方式构建网站会比较麻烦正在使用可为您修复所有链接的渲染系统(页面中希望保留会话的所有链接必须在查询参数中具有正确的会话ID),并且会抛出书签和许多其他问题。

But, this is much more cumbersome to build a site this way unless you are using a rendering system that fixes all the links for you (all links in the page that wish to preserve the session must have the right session id in the query parameter) and it throws off bookmarks and lots of other issues.

但是,快速会话并不是这样。它需要一个cookie。

But, express-session does not do it this way. It requires a cookie.

这篇关于Express会话可以不使用cookie进行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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