Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, I have trouble setting cookies domain. When I do they are not being saved. If I comment out the line of code that sets the domain the cookies are stored. I am trying to get my cookies stored with their same subdomain name in the cookies folder. Using XP prof, Visual Studio 2005. The domain name I use is correct for the subdomain of the web page running the server side script, but this example has a fictitious name. Maybe the server thinks the domain is different?? Or is "container" a keyword??
Thanks.
C#
protected void setCookie()
{  
 HttpCookie cookie = new HttpCookie("data");
 cookie.Domain = "container.mySite.com";
 cookie.Path = "/container";
   
 cookie.Values["tb1"] = TextBox1.Text;
 cookie.Expires = DateTime.Now.AddHours(1);
 Response.Cookies.Set(cookie);
}
Posted
Updated 17-Oct-13 7:43am
v2
Comments
ZurdoDev 17-Oct-13 14:14pm    
Why do you need the domain listed?
codeBlazer 17-Oct-13 15:33pm    
Hi Ryan, The reason is I have noticed for example that Yahoo will have multiple cookies stored in my cookie folder listed under differing subdomain names. I would like to do the same thing on my web pages and ultimately allow more data overhead for each cookie.
Thanks
Naman Kumar Sinha 17-Oct-13 18:03pm    
If you are sure that when the web page runs, the url looks something like this:
http://abc.container.mysite.com
then the code posted by you sould work correctly.
abc.container.mysite.com is subdomain of container.mysite.com
codeBlazer 17-Oct-13 20:43pm    
Hi Naman, Yes! You are right. Thank You! I hadn't made the subdirectories on the server (oops). Kudos!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900