I have multiple domains pointing to one Web application. Here are a few, just as an examples, so that I can reference them in my examples.

  • www.mydomain.com
  • sub.mydomain.com
  • www.affiliatedomain.com

ASP.NET allows for a web.config setting to accomplish this:

<httpCookies httpOnlyCookies="true" domain=".mydomain.com" />

This allows me to share sessions between the www.mydomain.com and mydomain.com domains. Perfect! Except it only works for one domain.

Another avenue I explored was url rewriting. I could insert a rewrite rule to ensure that only www urls are being accessed but doing so (at least the one I write) works for the domains, but appends a www. to the sub.mydomain.com resulting in a failed www.sub.mydomain.com - which won't work. Perhaps this option could still work if someone knows how to formulate url rewrite urls better than me.

Finally, to be clear, I don't need to share sessions across all domains (I know this is not possible). I just would like to share domains across the same domain with and without www.

For example: www.mydomain.com and mydomain.com

Or www.affiliatedomain.com and affiliatedomain.com

The sub.mydomain.com can live on its own so long as it never has a www. in front of it.

Related posts

Recent Viewed