Can a cookie be shared between two sites on the same top level domain? Say www.example.com and secure.example.com ?
We are looking into implementing a cache for non-secure content, and need to segregate secure content to another domain.
What parameters does the cookie need? I’m using asp.net
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Yes, you can. Use:
Response.Cookies("UID").Domain = ".myserver.com"
Method 2
The easiest way to apply a cookie domain that can be shared across subdomains is to put it in your web.config:
<forms cookieDomain="example.com">
Method 3
Yes, but beware don’t set same-named cookies in various subdomains, as the resulting cookie appears to be random; instead, set one cookie in the .maindomain.com only (not in any .sub.domain.com)
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0