Third-party cookies (including demo) and safaricookies are disabled by default in Safari later versions.

Source: Internet
Author: User

Third-party cookies (including demo) and safaricookies are disabled by default in Safari later versions.

Some time ago, I encountered a headache in the project, that is, the third-party cookies are blocked by default in the later version of Safari, this makes it impossible for users using the Safari browser to operate according to the normal business logic.

Problem display

Knowledge Point

What is a third-party cookie? When you access website A, website A is regarded as the first party. If website A references resources of another website B (the domain name of website B is different from the domain name of website, in this case, website B is considered a third party. It should be noted that the criteria for distinguishing different websites here are whether the domain names are the same, rather than whether the two websites are operated by the same company. For example, taobao.com and tmall.com are considered to be two websites, even though they all belong to Alibaba Group.

Problem demo

For reference only, create two basic MVC projects CookieSolution and TestCookieSolution. Assume that CookieSolution contains the normal business logic. There are two pages Page1 and Page2. The corresponding code is as follows:

        public ActionResult Page1()        {            Session["mySession"] = "Jackbase";            return View();        }        public ActionResult Page2()        {            if (Session["mySession"] != "Jackbase")            {                return Redirect("Page1");            }            return View();        }    

The background code is as follows:

@ * Front-end code of Page1 * @ 

We can see that the value of Session ["mySession"] is set in the initialization of Page1, and the value of Session ["mySession"] is detected in the initialization of Page2. If the value is incorrect, the value will jump back to Page1. Use iframe to reference the CookieSolution page on the page of TestCookieSolution. The front-end code is as follows:

Background

     public ActionResult Test()        {            return View();        }

Do not ask me what www.cookieSolution.com is. Add it in hosts.

127.0.0.1    www.cookieSolution.com

Everything is ready. Create two sites in IIS and bind CookieSolution (port 80) and TestCookieSolution (Port 8050)

Visit http: // localhost: 8050 for testing (based on the Safari browser). It is found that clicking Go to Page2 cannot jump to Page2, and it is still in Page1. The Safari Security Mechanism blocks third-party cookies and sessions. I have tried many methods on the Internet. What P3P is almost impossible...

Solution

Since the browser blocks third-party cookies and data, we can try to make the browser think that the page in iframe does not belong to a third party? Before entering the Test page, we first open a page in www.cookieSolution.com, set the cookie, and then jump to the Test page. Then www.cookieSolution.com is not a third party.

Add a page in TestCookieSolution, PreTest.

        public ActionResult PreTest()        {            return View();        }

Add a method in HomeController of CookieSolution

Public ActionResult CookieMaker () {// set a Session ["Prepare"] = "jb"; return Redirect (Request. QueryString ["url"]);}

This solves this problem. If you are interested, you can test it on your own. Here we will not show much.

References

Missing cookies on iframe in safari 5.1.5

Safari 3rd party cookie iframe trick no longer working?

Ipad Safari iframe cookie when the browser disables third-party cookies by default

Demo code used in this article

CookieSolution.zip

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.