mp3duck
mp3duck

Reputation: 2673

asp.net cookies subsites

How should I go about creating a cookie that can be read on my sites URL, and all subsites.

i.e. cookie called "myCookie" created on http://www.mysite.com/

Once created, it can then be read on http://site1.mysite.com/ and http://site2.mysite.com/ etc etc.

The above scenario should happen if the user has opted to "remember" their cookie. I am assuming that if the cookie isn't persisted, it will be "lost" when the change site.

The above sites are in their one IIS entries, and in my case, completely different servers.

Cheers!

EDIT:

I created my cookie on the sub-domain, so that fire cookie reads its domain as ".mysite.com".

The mainsite doesn't recongise this cookie, but I think it is their site that needs to change.

  1. Create the cookie so that my site can read it,
  2. Be able to read the cookie is my site creates it.

Upvotes: 1

Views: 345

Answers (1)

stephenbayer
stephenbayer

Reputation: 12431

You are going to need to fix your cookie domain on your PHP site. The subsites will not be able to read your cookies unless you do that. Since you are saying that your main site is in PHP and the cookie domain is "www.mysite.com", this will need to be done on the PHP side.

   ini_set('session.cookie_domain', 'mysite.com');

You are not going to be able to read it otherwise.

Upvotes: 1

Related Questions