IE浏览器下使用localhost域名保存cookie的问题
2016-12-02 19:49
555 查看
注:转载请注明出处,http://blog.csdn.net/huyi0616/article/details/53438435
最近在做一个新项目,发现在IE浏览器下无法单点登录,经过源码查看追踪,发现如下代码问题
SessionConfig.java
SessionManager.java
login.js
现象:
在chrome,firefox浏览器下,设置cookie的domain为localhost时是可以正常保存cookie,但IE是无法保存
总结:
1. 在cookie设置域名domain为localhost时,IE浏览器无法保存cookie
2. 设置项目代码为localhost时,使用http://localhost:8080/访问,不论你domain设置为什么,IE浏览器同样无法保存cookie
解决方案:
1.修改host文件,修改增加本地的域名对应到127.0.0.1
如:
2.不要使用localhost开发IE
最近在做一个新项目,发现在IE浏览器下无法单点登录,经过源码查看追踪,发现如下代码问题
SessionConfig.java
private Integer redisExpireTime = 60 * 60 * 24 * 7; private Integer cookieExpireTime = 60 * 60 * 2; private Integer cookieMaxAge = -1; private String cookieDomain = "localhost"; private String cookiePath = "/";
SessionManager.java
Cookie refreshTimeCookie = new Cookie(REFRESH_TIME_COOKIE_KEY, String.valueOf(System.currentTimeMillis())); refreshTimeCookie.setMaxAge(sessionConfig.getCookieMaxAge()); refreshTimeCookie.setPath(sessionConfig.getCookiePath()); refreshTimeCookie.setDomain(sessionConfig.getCookieDomain()); response.addCookie(refreshTimeCookie);
login.js
var login = function() { if(!$("#account").val() || !$("#pwd").val()) { $('#error-msg').text("用户名及密码不能为空.").show(); return; } var loginParam = $('#login-form').find('input').serialize(); console.log(loginParam); $.ajax({ method : 'POST', url : 'account/login', data : loginParam, success : function(result) { if (result && result.code=='0') { console.log(getUrlParameter('requestURL')); window.location.href = getUrlParameter('requestURL') + window.location.hash; $('#error-msg').text('').hide(); } else { $('#error-msg').text(result.msg).show(); } } }); }
现象:
在chrome,firefox浏览器下,设置cookie的domain为localhost时是可以正常保存cookie,但IE是无法保存
总结:
1. 在cookie设置域名domain为localhost时,IE浏览器无法保存cookie
2. 设置项目代码为localhost时,使用http://localhost:8080/访问,不论你domain设置为什么,IE浏览器同样无法保存cookie
解决方案:
1.修改host文件,修改增加本地的域名对应到127.0.0.1
如:
127.0.0.1 www.360qq.com
2.不要使用localhost开发IE
相关文章推荐
- 域名引起的IE cookie不能使用的问题
- ie 浏览器无法保存cookie,且与域名包含了下划线(_)有关系的问题
- IE中若域名中含下划线,则无法保存Cookie和Session问题
- Android使用Asynchronous Http Client完成登录保存cookie的问题
- ie 浏览器无法保存cookie,且与域名包括了下划线(_)有关系的问题
- linux系统安装hadoop-1.2.1遇到的问题【linux本机上的主机名和域名问题、不可以使用默认的localhost;完全没有启动】
- 使用Cookie登陆,保存Cookie,读取Cookie(C#)
- 开发Web应用程序中Cookie使用的问题
- 使用Cookie保存菜单状态
- 使用Cookie保存菜单状态
- acegi 登录ie时cookie不能保存, firfox可以使用
- 在解决动态切换皮肤的子域名Cookie保存问题过程中收集的一些参考资料
- 使用Application、Session、Cookie、ViewState和Cache等对象保存信息的区别
- 使用cookie解决重复投票的问题
- 在win2000下二级域名的cookie问题
- 使用保存文件对话框获取文件名的问题
- DNN使用非80端口和总是跳转到http://localhost问题的解决(翻译)
- win应用程序保存或使用Cookie
- 使用APPlication,Session,Cookie和ViewState等对象保存信息的区别是什么?
- Cookie使用中的一些要点及问题