0

I have a application that is running on abc.com and it is ssl.Same application is accessible from both url

  • https://example.com
  • https://**www.**example.com

My problem is that I am not able to share same session variable between both URL. For example: if I initialize a session on test.aspx.cs

session["UID"]=100;

and want to access it on test1.aspx.cs.

var test=session["UID"];

But I am not able to get same session when session is set using https://example.com/test.aspx and want to access it using https://www.example.com/test1.aspx.

Please help.

Ajeet
  • 9
  • 9
  • Sounds like you need to use an application variable instead of a session variable. The entire point of a session variable is that each session gets it's own. – Kevin Feb 17 '16 at 19:04
  • @Kevin I disagree. Application-state affects all users, Session-state is for a single visitor's session, in OP's case a session can cross domain names and he wants ASP.NET to support that scenario. – Dai Feb 17 '16 at 19:05

2 Answers2

0

The concept of Session only works because of the Session cookie. By default cookies do not cross subdomains.

See this previous QA for instructions on how to make cookies carry across subdomains: Share cookie between subdomain and domain

Community
  • 1
  • 1
Dai
  • 110,988
  • 21
  • 188
  • 277
  • Thanks a lot for your response. But I am not using any subdomain. Same application is being from both urls https://**example**.com and https://**www**.example.com. – Ajeet Feb 17 '16 at 19:23
  • @Ajeet "www.example.com" **is** a subdomain of "example.com" which is why the session cookie isn't being shared. – Dai Feb 17 '16 at 20:28
0

Is this a single server application or a multi-server application? What approach are you using for session state mode? Sounds like you could be using in process session management which doesn't span servers.

Kris
  • 111
  • 5