Why do entries in the host file create new SessionIDs for each request

给你一囗甜甜゛ 提交于 2019-12-08 05:30:17

问题


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

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

Everything seemed to be working fine, until I started working with the Session object. I discovered that after each request all my session variables were lost. Further investigation revealed that each response from the server contained a new SessionID.

Why is that?

I was able to hard code some flags to complete my testing using 'localhost' for requests without any problems.


回答1:


I can't explain it, but I have an acceptable work around to my own problem.

Rather than use 127.0.0.1 in the Host file I am using my local IP. So requests to the names in my host file are handled locally and I keep the same SessionID throughout the site.

If anyone else can explain I'd be happy to know what IIS (or asp.net) is doing when using 127.0.0.1.




回答2:


I think this has to do with the domain of the site and the session cookie passed - the browser won't pass a cookie sent to it from oldhostname.sample.com to newhostname.sample.com.

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

Alternatively, you could look into using cookie-less sessions. http://msdn.microsoft.com/en-us/library/aa479314.aspx



来源:https://stackoverflow.com/questions/4226568/why-do-entries-in-the-host-file-create-new-sessionids-for-each-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!