When I examine my HttpContext.Current.Request.Cookies collection, some of my cookies have null for their Domain member.
Why/when is a Domain null?
When I examine my HttpContext.Current.Request.Cookies collection, some of my cookies have null for their Domain member.
Why/when is a Domain null?
By default, Cookies are associated with the current domain.
So if on 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 scope of the domain:
Response.Cookies["AppCookie"].Domain = "bar.foo.com";
The cookie will then only be available to requests in that specific subdomain.
So of course, you can set the Domain to NULL, but i cant envision a scenario where this would be useful.
Check how you are creating your cookies.
Reference: http://msdn.microsoft.com/en-us/library/ms178194.aspx
The domain property is only for setting cookies. Obviously, if you are reading the cookie as part of the request, the client browser felt that the domain was appropriately matched to your site.