CORS: write and read a cookie through two website and client/server languages (javascript and ASP.NET C#)
<p>i have two web site:</p>

<ol>
<li>www.foo.com</li>
<li>www.bar.com</li>
</ol>

<p>on <code>www.bar.com/page.aspx</code> i set a session cookie with name "baz" and after redirect to <code>www.foo.com/page2.aspx</code>:</p>

<pre><code>// set the "baz" cookie 
Response.Cookies["baz"].Value   = "test";
Response.Cookies["baz"].HttpOnly = false;

// redirect to www.foo.com/page2.aspx
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location", "http://www.foo.com/page2.aspx");
</code></pre>

<p>on <code>www.foo.com/page2.aspx</code> i include a javascript from <code>www.bar.com</code>, eg:</p>

<pre><code>&lt;html&gt;
&lt;head&gt;
&lt;script src="//www.bar.com/script.js"&gt;&lt;/script&gt;
...
</code></pre>

<p><code>script.js</code> make an ajax request to <code>www.bar.com/ajax.aspx</code> (same server):</p>

<pre><code>var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", 'http://www.bar.com/ajax.aspx', true);
xmlhttp.send();
</code></pre>

<p>and <code>ajax.aspx</code> try to read "baz" cookie</p>

<pre><code>string cookie = Request.Cookies["baz"].Value
</code></pre>

<p>but "baz" cookie is <code>null</code>!</p>

<p>if i open <code>www.bar.com/ajax.aspx</code> into browser the cookie is read correctly.</p>

<p>it's a CORS problem? how solve it?</p>