域名后的查询字符串

发布于 2024-08-23 18:55:46 字数 560 浏览 2 评论 0原文

我试图在超链接控件的 URL 末尾添加一个查询字符串,如下所示

HyperLink testLink = new HyperLink();
testLink.NavigateUrl = "http://www.example.com" + "?siteId=asd343s32kj343dce";

但是当它在浏览器中呈现时,它显示为 http://www.example.com/?siteId=asd343s32kj343dce.com 后面的 / 字符)。

如果 testLink.NavigateUrl = "http://www.example.com/abc.aspx" + "?siteId=asd343s32kj343dce";

那么链接将正确呈现为 http:// /www.abcd.com/abc.aspx?siteId=asd343s32kj343dce(无多余字符)。

我错过了什么吗?请指教。

谢谢你, 克里希纳。

I am trying to add a query string at the end of URL for a hyperlink control as follows

HyperLink testLink = new HyperLink();
testLink.NavigateUrl = "http://www.example.com" + "?siteId=asd343s32kj343dce";

But when this is rendered in the browser it is displaying as
http://www.example.com/?siteId=asd343s32kj343dce (/ char after the .com).

And if the testLink.NavigateUrl = "http://www.example.com/abc.aspx" + "?siteId=asd343s32kj343dce";

Then the link is rendered correctly as http://www.abcd.com/abc.aspx?siteId=asd343s32kj343dce (No extra characters).

Am I missing any thing? Please advice.

Thank you,
Krishna.

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

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

发布评论

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

评论(4

青朷 2024-08-30 18:55:46

浏览器会假设域名后面应该有一个斜杠,从而为您更正 URL。您可能会遇到不执行此操作的浏览器的问题,因此您应该将 URL 更正为:

testLink.NavigateUrl = "http://www.abcd.com/" + "?siteId=asd343s32kj343dce";

斜线应位于域名后面的原因是域名本身不能是资源。域名仅指定网站,URL 必须具有指定该网站上的资源的内容,斜杠指定网站根文件夹中的默认页面。

The browser is correcting the URL for you by assuming that there should be a slash after the domain name. You might run into problems with browsers that doesn't do this, so you should correct the URL to:

testLink.NavigateUrl = "http://www.abcd.com/" + "?siteId=asd343s32kj343dce";

The reason that the slash should be after the domain name is that the domain name itself can not be a resource. The domain name just specifies the web site, the URL has to have something that specifies a resource on that site, and the slash specifies the default page in the root folder of the site.

三五鸿雁 2024-08-30 18:55:46

这是正常的,/ 告诉您域名已结束,您现在位于网站的结构内(在本例中为根上下文)。

第二个是正常的,因为 abc.aspx 是一个网页,它可以接受查询字符串。域不能接受查询字符串。

this is normal, the / tell that the domain name ended and you are now inside the structure of the website (root context in this case).

the second one is normal because abc.aspx is a webpage and it can accept querystring. a domain cannot accept a querystring.

羁客 2024-08-30 18:55:46
An HTTP URL takes the form:

http://<host>:<port>/<path>?<searchpart>

where <host> and <port> are as described in Section 3.1. If :<port>
is omitted, the port defaults to 80.  No user name or password is
allowed.  <path> is an HTTP selector, and <searchpart> is a query
string. The <path> is optional, as is the <searchpart> and its
preceding "?". If neither <path> nor <searchpart> is present, the "/"
may also be omitted.

https://www.rfc-editor.org/rfc/rfc1738#section- 3.3

An HTTP URL takes the form:

http://<host>:<port>/<path>?<searchpart>

where <host> and <port> are as described in Section 3.1. If :<port>
is omitted, the port defaults to 80.  No user name or password is
allowed.  <path> is an HTTP selector, and <searchpart> is a query
string. The <path> is optional, as is the <searchpart> and its
preceding "?". If neither <path> nor <searchpart> is present, the "/"
may also be omitted.

https://www.rfc-editor.org/rfc/rfc1738#section-3.3

撞了怀 2024-08-30 18:55:46

尽管 http://example.com?query 是有效的 URI。 HTTP URI 的规范化指出 http: //example.com?queryhttp://example.com/?query 相等:

[…]因为“http”方案使用了权限组件,默认端口为“80”,并定义了一个空路径等效于“/”,所以以下四个URI是等效的:
<前><代码> http://example.com
http://example.com/
http://example.com://
http://example.com:80/

一般来说,使用通用语法的权限且路径为空的 URI 应规范化为“/”路径。

Although http://example.com?query is a valid URI. The normalization of HTTP URIs states that http://example.com?query and http://example.com/?query are equal:

[…] because the "http" scheme makes use of an authority component, has a default port of "80", and defines an empty path to be equivalent to "/", the following four URIs are equivalent:

  http://example.com
  http://example.com/
  http://example.com:/
  http://example.com:80/

In general, a URI that uses the generic syntax for authority with an empty path should be normalized to a path of "/".

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