网址哈希在重定向之间持续存在 [英] URL hash is persisting between redirects
问题描述
出于某种原因,非IE浏览器在发送服务器端重定向时(使用位置标头)似乎会保留URL哈希(如果存在)。例如:
//使用Response.Redirect进行简单重定向(http://www.yahoo.com);
Text.aspx
如果我拜访:
Test.aspx#foo
在Firefox / Chrome,我被带到:
http://www.yahoo.com#foo
code>
任何人都可以解释为什么会发生这种情况吗?我已经尝试过在不同的平台上使用不同的服务器端重定向(虽然都是位置标题),这似乎总是会发生。我在HTTP规范中没有看到它,但它确实似乎是浏览器本身的一个问题。 URL哈希(如预期的)永远不会发送到服务器,所以服务器重定向不会受到它的污染,浏览器只是由于某种原因持久保存它。
任何想法?
我建议这是正确的行为。 302和307状态码表明该资源将在别处找到。 #bookmark
是资源中的一个位置。
一旦找到资源(html文档),浏览器就可以找到 #bookmark
文件。
比喻是这样的:你想在第57章的书中看一些东西,所以你去图书馆去买书。但是书架上有一张纸条说明这本书已经移动,现在在另一座建筑物中。所以你去了新的位置。你仍然想要第57章 - 这与你拿到书的位置无关。
For some reason, non IE browsers seem to persist a URL hash (if present) when a server-side redirect is sent (using the Location header). Example:
// a simple redirect using Response.Redirect("http://www.yahoo.com");
Text.aspx
If I visit:
Test.aspx#foo
In Firefox/Chrome, I'm taken to:
http://www.yahoo.com#foo
Can anyone explain why this happens? I've tried this with various server side redirects in different platforms as well (all resulting in the Location header, though) and this always seems to happen. I don't see it anywhere in the HTTP spec, but it really seems to be a problem with the browsers themselves. The URL hash (as expected) is never sent to the server, so the server redirect isn't polluted by it, the browsers are just persisting it for some reason.
Any ideas?
I suggest that this is the correct behaviour. The 302 and 307 status codes indicate that the resource is to be found elsewhere. #bookmark
is a location within the resource.
Once the resource (html document) has been located it is for the browser to locate the #bookmark
within the document.
The analogy is this: You want to look something up in a book in chapter 57, so you go to the library to get the book. But there is a note on the shelf saying the book has moved, it is now in the other building. So you go to the new location. You still want chapter 57 - it is irrelevant where you got the book.
这篇关于网址哈希在重定向之间持续存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!