search

Home  >  Q&A  >  body text

node.js - 客户端页面跳转后session丢失

RT,登录页面中提交请求


对应的路由处理

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

PHP中文网PHP中文网2866 days ago891

reply all(5)I'll reply

  • ringa_lee

    ringa_lee2017-04-17 12:11:08

    Check whether it jumps under the same domain name

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 12:11:08

    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

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 12:11:08

    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

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 12:11:08

    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

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 12:11:08

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

    reply
    0
  • Cancelreply