Share Cookies Between Subdomains on .NET

Hello,

Here is quick tip:

If you use the simplest way to write a cookie on ASP.NET:
Response.Cookies.Set(New HttpCookie("TestCookie", "TestData"))
It will be only readable by the subdomain that you used to write the cookie…

If you want the cookie to be read by any subdomain (of the current site) you have to prepend a “.” before the domain value on the cookie…
Example:
Dim cookie As New HttpCookie("ActivePremiumUser", "ItsActive")
cookie.Domain = ".domain.com"
Response.Cookies.Set(cookie)

AC.

This entry was posted in .Net Coding, Basic Technical and tagged , , , , , . Bookmark the permalink.

Comments are closed.