为什么主机文件中的条目会为每个请求创建新的 SessionID

发布于 2024-10-03 13:21:12 字数 367 浏览 0 评论 0原文

我正在对我们的一个网站进行更新。此版本将根据请求中的主机名具有独特的行为。为了测试此行为,我通过添加指向我的计算机的条目来修改我的计算机主机文件。

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

一切似乎都工作正常,直到我开始使用 Session 对象。我发现每次请求后我的所有会话变量都会丢失。进一步调查显示,来自服务器的每个响应都包含一个新的 SessionID。

这是为什么?

我能够对一些标志进行硬编码,以使用“localhost”来完成我的测试,而不会出现任何问题。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你与昨日 2024-10-10 13:21:12

我认为这与站点的域和传递的会话 cookie 有关 - 浏览器不会传递从 oldhostname.sample.com 发送到 newhostname.sample.com 的 cookie。

要解决此问题,您需要设置发送的会话 cookie 的域。这个问题应该展示如何做到这一点 - ASP.NET Session Cookies - 指定基本域

或者,您可以考虑使用无 cookie 会话。 http://msdn.microsoft.com/en-us/library/aa479314。 ASPX

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

孤独岁月 2024-10-10 13:21:12

我无法解释它,但我有一个可以接受的解决方案来解决我自己的问题。

我没有在主机文件中使用 127.0.0.1,而是使用我的本地 IP。因此,对我的主机文件中的名称的请求是在本地处理的,并且我在整个站点中保留相同的 SessionID。

如果其他人可以解释,我很乐意知道 IIS(或 asp.net)在使用 127.0.0.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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文