Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query string after the domain name

Tags:

http

url

uri

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.

like image 469
Krishna Avatar asked Mar 05 '10 18:03

Krishna


3 Answers

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.

like image 84
Guffa Avatar answered Sep 21 '22 15:09

Guffa


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.

like image 33
Fredou Avatar answered Sep 17 '22 15:09

Fredou


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

like image 24
meloniq Avatar answered Sep 20 '22 15:09

meloniq