Internet Explorer中的快速会话

我像这样configuration快速会话插件:

var express = require('express'), session = require('express-session'), uuid = require('node-uuid'); var expiration_day = new Date('9/15/2015'), today = new Date(), session_life = Math.abs(expiration_day.getTime() - today.getTime()); var config = { name: 'mycookie', // session ID cookie name key: 'mycookie', // session ID cookie name secret: '$FGDFH$W#WEgfgdf', hash: { salt: '9883hjHFIDSU&U#H' }, store: new MongoStore({mongooseConnection: db}), unset: 'keep', //never remove expired sessions saveUninitialized: true, //always create session, even if nothing is stored resave: false, //don't save session if unmodified ttl: session_life, autoRemove: 'disabled', //disable expired sessions cleaning genid: function (req) { "use strict"; return uuid.v4(); }, cookie: { path: '/api', // cookie will be stored for requests under '/api' httpOnly: false, domain: 'example.com', secure: false, expires: expiration_day, maxAge: session_life } }; app.sessionMW = session(config);//session middleware 

在Chrome和Mozilla Firefox浏览器中,只有一个会话是为用户创build的。 此会话在所有使用sessionMW中间件的路由上都可用。 因此,如果您对/ api / users /或/ api / sessions执行GET或POST请求,则相同的会话ID将存储在Cookie中,并会发送到每个请求的Cookie标头中。

Internet Explorer不能这样工作。 对于每个请求,创build一个新的会话。 会话存储在服务器上,我已经确认浏览器中有一个新的cookie用于应用程序的每个路由。

我已经在cookies中定义了域名,path和到期date。 IE中的cookie显示这些值。

我不使用cookieParser,所以不能成为问题。

无论如何,这个问题似乎在客户端。 Internet Explorer不发送带请求的Cookie标头。 它在每个请求的响应中接收set-cookie标头。 但是数据不会在后续请求中重复使用。

这可能是一个CORS的问题? 该cookie不是针对我运行该应用程序的同一个域。 我需要在另一个域上托pipe的API的所有路由的会话。

客户端configuration为在CORS请求中包含cookie:

 $.ajaxSetup({ cache: false, xhrFields: { withCredentials: true //all AJAX requests should include Cookie data } }); 

我发送这些接受控制标题的响应每个请求:

Access-Control-Allow-Credentials:true

Access-Control-Allow-Headers:Origin,X-Requested-With,Content-Type,

接受Access-Control-Allow-Methods:OPTIONS,GET,POST,PUT,PATCH

Access-Control-Allow-Origin: http : //example.com

为什么IE不在请求中设置Cookie头? 该域的名称中没有下划线,并且不以数字开头。

确保你的服务器的时区和时间是正确的。 我只是debugging了一个问题,其中服务器的时间是本地的,但时区设置为UTC。 不知何故,Chrome浏览器和Firefox仍然正确解释到期,但IE尊重UTC时区,所以cookie已经过期了。 请注意,如果您在与UTC有关的负时区中,它只会立即过期。

强调你的域名也可能导致这个问题。

IE和Edge不存储包括下划线在内的域名的cookie。