开发者

Why do some cookies have a '.' before the domain?

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?


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜