Cookie sharing between different ports

I have application 1 (C #) hosted on port: 80 and application 2 (nodejs) hosted on port: 3030. Both are on the local host.

The request workflow is as follows:

  • The browser sends a request to the application 1
  • application 1 sends back the number of cookies
  • later the browser sends a request to application 2
  • ^ The problem is at the last step, the cookie is not included in the request.

Things I tried / understood:

  • I understand that this is a restriction on policies of the same origin, and because of different ports # the browser considers them as different domains.
  • In Appendix 1 (using System.Web.HttpCookie) I tried to set a specific port for the domain ("127.0.0.1:3030"), but it looks like the browser is not accepting it or ignoring it.

    //c# code
    var testCookie1 = new HttpCookie("Test", "testValue");
    testCookie1.Domain = "127.0.0.1:3030";
    testCookie1.Path = "/";
    testCookie1.Expires = DateTime.Now.AddDays(1);
    Response.SetCookie(testCookie1);
    
    var testCookie2 = new HttpCookie("Test2", "testValue2");
    testCookie2.Domain = "127.0.0.1";
    testCookie2.Path = "/";
    testCookie2.Expires = DateTime.Now.AddDays(1);
    Response.SetCookie(testCookie2);
    

Cookies returned from the server Cookies stored in the browser

The server sends back a cookie with the port number attached to it, but the browser seems to ignore it.

and here are my ajax calls:

   var request = $.ajax({
        url: 'http://127.0.0.1:3030/SomeTask',
        type: 'POST',
        crossDomain: true,
    });
+6
source share
3 answers

In this case, your domain will be the same as localhost, so there should be no problems.

Another thing: the port is part of the URI, not the domain, the domain is also part of the URI, so you mix apples and fruits ...

Refer to this other question in SO

rfc clearly states

Introduction

cookie . , , "" , Secure . , cookie , " ", -, , .

.

( ),

var testCookie1 = new HttpCookie("Test", "testValue"); testCookie1.Domain = "." + mydomain;

, x.mydomain y.mydomain cookie.

, cookie localhost ipaddress.

, :

127.0.0.1   myawesomesubdomain.thisdomainnotexist.com.tr

cookie

+3

, , app1.myapp.com app2.myapp.com, myapp.com.

, :

127.0.0.1 app1.myapp.com
127.0.0.1 app2.myapp.com

, C:\Windows\System32\drivers\etc /etc/hosts

+1

, :

  • Apache .
  • Disable security (i.e. the same origin policy) in browsers.
+1
source

All Articles