在非同源的iframe存储不上cookie
需求描述: 公司的系统A需要嵌入公司系统B的页面。 系统A为C#程序,启动在IIS。在系统A中一个页面通过
iframe嵌入系统B的页面,系统B是shiro的安全框架,前后端接口身份验证通过后端在response设置cookie存
储上Jsessionid。 在谷歌浏览器中存在保护机制,当不同源的页面时无法在子页面存储cookie。导致在嵌套页面无
法正常访问接口。
解决方法: 在请求头加入p3p(可自行百度)没有成功。 最后通过测试发现如果是同源的界面则可以存储上cookie。
同源策略(可自行查询 跨域相关知识 简单说就是 http协议 + IP + 端口 + 域名都要相同才可以算是同源)。最
后通过nginx配置转发代理实现同源解决问题。
server {
listen 10000;
#location ~ ^/login[^.]+ {
#location ~ ^/[a-z]+/login$ {
location ^/(?!(pms|platform))[^/]+/login$ {
rewrite .* /login/login.html;
}
location / {
add_header Cache-Control no-cache;
root D:\pms-hzj\hzx-front-pc;
index login.html;
}
location /pms/teamwork {
proxy_pass http://192.168.0.191:12002/pms-teamwork;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /pms {
proxy_pass http://192.168.0.191:12001/pms;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /pms/enterbid {
proxy_pass http://192.168.0.191:12005/pms-enterbid;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /pms/tender{
proxy_pass http://192.168.0.191:12004/pms-tender;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /pms/supervise{
proxy_pass http://192.168.0.191:12006/pms-supervise;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
#error页面
error_page 404 /404.html;
}
server {
listen 5555;
#location ~ ^/login[^.]+ {
#location ~ ^/[a-z]+/login$ {
location ^/(?!(pms|platform))[^/]+/login$ {
rewrite .* /login/login.html;
}
location / {
proxy_pass http://127.0.0.1:14725;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /hzj {
proxy_pass http://192.168.0.200:10000/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /js {
proxy_pass http://192.168.0.200:10000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /css {
proxy_pass http://192.168.0.200:10000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /images {
proxy_pass http://192.168.0.200:10000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /login {
proxy_pass http://192.168.0.200:10000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /pms {
proxy_pass http://192.168.0.200:10000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /sys {
proxy_pass http://192.168.0.200:10000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /teamwork {
proxy_pass http://192.168.0.200:10000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /enterbid {
proxy_pass http://192.168.0.200:10000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /tender {
proxy_pass http://192.168.0.200:10000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /supervise {
proxy_pass http://192.168.0.200:10000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
#error页面
error_page 404 /404.html;
}