Read Cookies from another domain using Javascript and ASP.NET
Reading cookies from another domain is a security risk, in terms of session hijacking, however, there may be reasons why you may want to do this.
Here is a simple technique that allows Cookies to be read from one domain that have been set on another domain.
First, add an ASPX page with the content shown below, and save it as “xdom.aspx” in the root of your domain (“domain-A”)
var pairs = “<% Response.Write(Request.ServerVariables[“HTTP_COOKIE”]);%>”.split(“;”);
var cookies = {};
for (var i = 0; i < pairs.length; i++) {
var pair = pairs[i].split(“=”);
cookies[pair[0]] = unescape(pair[1]);
}
Then add a html file to another domain (“domain-B”)
<script src=”http://domain-A/xdom.aspx”></script>
<script language=”javascript”>
console.log(cookies);
</script>
Running this in Google Chrome, open developer console, and then expand out “object” and you’ll see the cookies that were set on “domain-A”