views:

64

answers:

3

Trying to share cookies accross 2 domains in asp.net, for some reason 1 domain has a '.' before the domain, and the other doesn't.

Why is that?

e.g:

.staging.example.com

and

staging.example.com

Is this something to do with how I create the cookie, or a web.config change?

I am not using forms authentication, just creating a cookie manually.

Upd

I am setting the cookie domain like:

HttpCookie c = new HttpCookie("blah");
c.Value = "123";
c.Expires = DateTime.Now.AddHours(12);
c.Domain = ".staging.example.com";

Response.Cookies.Add(c);

For some reason not getting the '.' in the cookie.

What could be the issue?

+1  A: 

The cookie for .staging.example.com is also readable for each subdomain of that domain, e.g. www.staging.example.com, the other one is not.

Residuum
+2  A: 

If you set a . before a domain name, e.g.

.staging.example.com

This means that any domain name that resides under that, will have access to that cookie. E.g. test01.staging.example.com would have access to whatever was in that cookie as if it had created it itself. Without the dot, its limited to the specific domain that is named.

Amadiere
+1  A: 

To make the cookie available on all subdomains of staging.example.com then you'd set it to .staging.example.com

Bryan Denny