node.js - 客户端页面跳转后session丢失
PHP中文网
PHP中文网 2017-04-17 12:09:08
0
5
841

RT,登录页面中提交请求


对应的路由处理

我把从数据库里取出来的account信息放到了session中,然后返回成功状态和一个重定向url,然后在action中直接用window.location.href = redirecurl来跳转,服务端能收到get请求,但是req.session中得account信息却丢失了,这是为什么???

PHP中文网
PHP中文网

认证0级讲师

reply all(5)
左手右手慢动作

Check whether it jumps under the same domain name

巴扎黑

The default cookie name corresponding to the session in express is a fixed value. If you deploy multiple express applications on a domain name but do not set the session cookie name, they will conflict with each other, so you should set it:

app.use(session({
    secret: '这里是加密参数',
    key:'session对应的cookie名称',
    resave: false,
    saveUninitialized: true
})
);

The above example is based on express4.0

伊谢尔伦

Obviously the session id is lost. It is speculated that the set cookie attribute in the http response header is not updated, resulting in the session id not being returned to the client. Grab a packet and see if the server also puts the session id in the header of the response when sending the redirect response. Then check to see if the client brings the session id when redirecting and requesting the server

Ty80

If there are multiple servers, the session will be lost. Ask your server engineer
to study the principles of cookies and sessions, and you will understand

巴扎黑

A session is essentially an ID, either in post/get or in cookies. You can open the debugging tool to see what is sent

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template