ASP.NET: Do cookie requests have null for domain?

When I look through my HttpContext.Current.Request.Cookies collection, some of my cookies have zero for my domain member.

Why / when is the domain null?

+6
source share
2 answers

The domain property is for setting cookies only. Obviously, if you read the cookie as part of the request, the client browser considers that the domain has been properly mapped to your site.

+8
source share

By default, cookies are associated with the current domain.

So if the site

www.foo.com

and you do the following:

HttpCookie appCookie = new HttpCookie("AppCookie"); appCookie.Value = "written " + DateTime.Now.ToString(); appCookie.Expires = DateTime.Now.AddDays(1); Response.Cookies.Add(appCookie); 

The domain will be

www.foo.com

.

However, you can override this functionality by setting the domain scope:

 Response.Cookies["AppCookie"].Domain = "bar.foo.com"; 

Then the cookie will be available only for requests in this particular subdomain.

So, you can set the Domain to NULL, but I cannot imagine a scenario where this would be useful.

Check how you create cookies.

Link: http://msdn.microsoft.com/en-us/library/ms178194.aspx

0
source share

All Articles