Response.Redirect(“~/...”) 在 HTTP 响应中到底放入了什么?
我刚刚读完 URL、URI 与 URN,用更简洁的术语来说,这确实有助于理解这三个术语之间的区别。从那时起,我浏览了 RFC2141 和 RFC2616 规范和 Microsoft 的 Response.Redirect Method 文档,努力自信地回答以下问题。
给定这行代码:
Response.Redirect("~/Foo.aspx");
以及生成的 HTTP 响应(针对上下文进行了修剪):
状态=找到 - 302 日期=11 月 24 日星期三
2010 17:27:58 GMT
服务器=Microsoft-IIS/6.0
X-Powered-By=ASP.NET
X-AspNet-版本=2.0.50727
位置=/MyWebApp/Foo.aspx
什么名称最能正确描述“位置”标头中放置的内容?
URL?统一资源定位符?瓮? URC?是哪一个?
I've just finished reading URL vs. URI vs. URN, in More Concise Terms, and it's really helped understand the distinction between the three terms. Since then I've skimmed the RFC2141 and RFC2616 specs and Microsoft's Response.Redirect Method documentation in an effort to answer the following question confidently.
Given this line of code:
Response.Redirect("~/Foo.aspx");
And this resulting HTTP response (trimmed for context):
Status=Found - 302 Date=Wed, 24 Nov
2010 17:27:58 GMT
Server=Microsoft-IIS/6.0
X-Powered-By=ASP.NET
X-AspNet-Version=2.0.50727
Location=/MyWebApp/Foo.aspx
What name(s) most properly describes what has been placed into the "Location" header?
URL? URI? URN? URC? Which is it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这是一个相对 URI。
它也是一个 URL,因为它可以在这种情况下用来定位资源并识别它,但现在讨论 URL 确实没有什么价值 - 区别更多的是你用它做什么而不是做什么它就其本身而言,并且 URL 始终是 URI。
It's a relative URI.
It's also a URL since it can be used in this context to locate the resource as well as identifying it, but really there's little value in talking about URLs these days - the distinction is more a matter of what you're doing with it than what it is in itself, and a URL is always a URI.
这是一个棘手的问题。就其本身而言(作为字符串),Location 是一个 URI,但您必须考虑定义它的上下文(即响应标头列表)
本质上,元组(browser::request::protocol、browser::request::domain、response::locationHeader)构成了一个 URL,因为 request 添加了检索机制。
It's a tricky question. On its own (as a string) Location is a URI, but you have to take into account the context in which it is defined (that being the response header list)
In essence a tuple (browser::request::protocol, browser::request::domain, response::locationHeader) constitutes a URL as request adds a retrieval mechanism.
~/ 被解析为 /MyWebApp/Foo.aspx,它没有声明涉及的机制是 HTTP;它声明的只是被重定向到的位置 - 这使得它成为一个 URL,尽管它没有明确指出其中的 http:// 。
~/ is resolved to /MyWebApp/Foo.aspx, which doesn't declare the mechanism involved being HTTP; all it declares is the location that is being redirected to - which makes it a URL, though it's not explicitly stating http:// in there.
Location 标头属性中的 URL 是根相对 URL。 ~/ 指定使用 ~/foo.aspx 创建的 URL 应相对于 IIS 中的应用程序目录为根目录。
The URL in the Location header property is a root-relative URL. The ~/ specifies that the URL being created with ~/foo.aspx should be root-relative to the application directory in IIS.
它是一个 Url,因为
~/
的解析提供了查找资源的位置和机制(“http”),但是标头值 Location 被设计为采用 Uri。标头字段定义
It is an Url since the resolution of
~/
provides both the location and the mechanism ("http") to find the resource, however, the header value Location is designed to take an Uri.Header Field Definitions