Transferring a session to another subdomain

In C #, how can I transfer a session from one subdomain to another subdomain? For example, I use localhost IIS and I tried to send a value from

http:\\localhost\site1 to http:\\localhost\site2

using the following method

 In site1 Session["test"] = "My value"; In site2 Response.Write(Convert.ToString(Session["test"])); 

The above method worked perfectly to transfer values ​​from one page to another, but I need values ​​that must be transferred from one subdomain to another sub-domain, i.e. one IIS web application to another IIS web application.

+4
source share
3 answers

You cannot do this with the default session state providers. You will have to collapse yourself using the provider model (SessionStateStoreProvider): here

You also can NOT use the provider model and do something like this

EDIT HAKE: I think you can do it. here

+1
source

I am doing something similar by exchanging session id (and related settings) through a shared database.

those.

  • site 1 writes its session identifier to the database table along with all the necessary related parameters, such as test in the example above.
  • site 1 calls the URL on site 2, passing the session ID of site 1 as a query string parameter.
  • site 2 collects the session identifier, which is passed as a query string parameter.
  • site 2 uses the session identifier as a search key in the database table to get the test value ("My value" in your example)

To increase security, I also write the timestamp of the table and allow site 2 to read only those lines where the session identifier and timestamp match (with some tolerance). In addition, site 2 deletes the record after reading it.

Of course, this is not straightforward and maybe not 100% of what you want to achieve, maybe this will be some idea.

0
source

The session is application specific. Can you send messages from site1 to site2 (for example, through jQuery). A message will allow you to send data (hidden). Then assign the request in your message a new session variable on site2.

0
source

Source: https://habr.com/ru/post/1391684/


All Articles