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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With