Cross-Site cookie loss caused by Ajax loading subdomains.

Source: Internet
Author: User

We have two websites: main.xxx.cn and prevei?xxx.cn.

The main.xxx.cn page needs to load the content of preview.xxx.cn.

There are two ways to load preview.xxx.cn content in the project. One is IFRAME and the other is Ajax.

1. IFRAME loading requires that document. Domain = be set to the root domain name xxx.cn on both pages.
(Other thickbox Magnific Popup. If the page under the same domain name is loaded, the document. Domain owner needs to be set, which also causes JS access failure. Because the domain name has been changed ).

2. Set Orign during Ajax loading.

Fresponse. addheader ("access-control-allow-origin", origin );

The origin tag can be seen through firebug about HTTP (s): // main.xxx.cn can also be used *

However, if this parameter is set only, the original cookie value of preview.xxx.cn cannot be passed. You need to set withcredentials as follows. In addition, the orgin value must be set to exactly the same, and the wildcard * cannot be used *.

You also need to add an httpheader.
Response. addheader ("access-control-allow-credentials", "true ");

$. Ajax ({
URL: 1. aspx
Datatype: "html ",
Xhrfields :{
Withcredentials: True
},

}

 

Cross-Site cookie loss caused by Ajax loading subdomains.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.