Google Chrome 和 Response.RedirectPermanent
我刚刚遇到一个问题,花了一些时间才弄清楚,并想为可能有相同问题的其他人记录下来。
我们的网站可以在不同的国家/地区使用,因此我们的 URL 如下所示:
http://www.example.com/
http://www.example.com/CA
http://www.example.com/UK
第一个自动转到美国。我们使用 cookie 来记住他们的国家/地区,以便当他们稍后返回网站 (http://www.example.com) 时,我们会将他们重定向到 (http://www.example.com/CA
)要返回美国版本,他们单击这样的链接 (http://www.example.com/US),该链接会设置 cookie 并重定向回主网站,因为美国版本通常没有国家/地区代码。
在进行这些重定向时,如果他们单击/US 链接,我们将执行以下操作:
SetCookie("US");
Response.RedirectPermanent("/");
当他们切换到加拿大(有效)然后尝试切换回美国时,问题就出现了。回答如下。
I just ran across a problem that took a little while to figure out and wanted to document it for someone else that may have the same issue.
Our site can be used in different countries, so we have URLs that look like this:
http://www.example.com/
http://www.example.com/CA
http://www.example.com/UK
The first automatically goes to the US. We use a cookie to remember their country so that when they come back to the site later (http://www.example.com), we redirect them to (http://www.example.com/CA)
When someone wants to go back to the US version, they click a link like this (http://www.example.com/US) which sets their cookie and redirects back to the main site because the US one normally doesn't have the country code.
In doing these redirects, we would do the following if they clicked the /US link:
SetCookie("US");
Response.RedirectPermanent("/");
The problem came when they switched to Canada (which worked) and then tried to switch back to the US. Answer below.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题出在谷歌浏览器上。因为我们使用了永久重定向,所以它甚至不会发送 http://www.example.com/US到浏览器。它基本上说:
因此,解决方法是使用 Response.Redirect (302) 而不是 Response.RedirectPermanent (301)。
The problem came with Google Chrome. Because we used a permanent redirect, it would not even send http://www.example.com/US to the browser. It said basically:
So the fix was to use Response.Redirect (302) instead of Response.RedirectPermanent (301).