Why host file entries create new SessionID for each request

I am working on an update on one of our sites. This version will have unique behavior based on the host name in the request. To test this behavior, I changed the host file of my computers by adding entries that point to my computer.

127.0.0.1 newhostname.sample.com 127.0.0.1 oldhostname.sample.com 

Everything seemed to work fine until I started working with the Session object. I found that after every request all my session variables were lost. Further research showed that each response from the server contained a new SessionID.

Why is this?

I managed to hardcode some flags to complete the test using "localhost" for requests without any problems.

+1
source share
2 answers

I cannot explain this, but I have an acceptable job for my own problem.

Instead of using 127.0.0.1 in the Host file, I use my local IP address. Therefore, name queries in my host file are processed locally, and I keep the same SessionID throughout the site.

If anyone else can explain, I would be happy to know what IIS (or asp.net) does when using 127.0.0.1.

0
source

I think this is due to the site domain and the session cookie passed - the browser does not pass the cookie sent to it from oldhostname.sample.com to newhostname.sample.com.

To fix this, you need to set the domain of the session cookie to send. This question should show how to do this - ASP.NET Session Cookies - specifying the base domain .

Alternatively, you can explore the use of sessions without cookies. http://msdn.microsoft.com/en-us/library/aa479314.aspx

0
source

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


All Articles