域名后的查询字符串
我试图在超链接控件的 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 ashttp://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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
浏览器会假设域名后面应该有一个斜杠,从而为您更正 URL。您可能会遇到不执行此操作的浏览器的问题,因此您应该将 URL 更正为:
斜线应位于域名后面的原因是域名本身不能是资源。域名仅指定网站,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:
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.
这是正常的,/ 告诉您域名已结束,您现在位于网站的结构内(在本例中为根上下文)。
第二个是正常的,因为 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.
https://www.rfc-editor.org/rfc/rfc1738#section- 3.3
https://www.rfc-editor.org/rfc/rfc1738#section-3.3
尽管
http://example.com?query
是有效的 URI。 HTTP URI 的规范化指出http: //example.com?query
和http://example.com/?query
相等:Although
http://example.com?query
is a valid URI. The normalization of HTTP URIs states thathttp://example.com?query
andhttp://example.com/?query
are equal: