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
Asked
Active
Viewed 9,154 times
20

pgb
- 24,813
- 12
- 83
- 113
-
2Note: This can cause [bugs or security issues](http://security.stackexchange.com/q/12412/396) depending on the cookie content. [More info here](http://stackoverflow.com/q/9636857/328397) – makerofthings7 Mar 11 '12 at 17:12
3 Answers
23
Yes, you can. Use:
Response.Cookies("UID").Domain = ".myserver.com"

pgb
- 24,813
- 12
- 83
- 113

Rich Bradshaw
- 71,795
- 44
- 182
- 241
5
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">

Jess Chadwick
- 2,373
- 2
- 21
- 24
-
Yeah, the spec is quite annoying. If you want to use example.com as your main domain, you can't then use static.example.com for your (cookieless) static files, and are forced to register another domain. – UpTheCreek Jan 12 '11 at 18:08