Query string after domain name

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

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

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

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

Then the link displays correctly as http://www.abcd.com/abc.aspx?siteId=asd343s32kj343dce (without additional characters).

Did I miss something? Please advice.

Thank you Krsna.

+4
source share
4 answers

The browser corrects the URL for you, assuming there must be a slash after the domain name. You may have problems with browsers that don't, so you should fix the url:

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

The reason the slash must be a domain name is because the domain name itself cannot be a resource. The domain name simply indicates the website, the URL must have what the resource on this site indicates, and the slash indicates the default page in the root folder of the site.

+4
source

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

the second is normal because abc.aspx is a web page and it can accept querystring. The domain cannot accept the request.

+3
source
 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. 

http://tools.ietf.org/html/rfc1738#section-3.3

+1
source

Although http://example.com?query is a valid URI. Normalizing the HTTP URI indicates that http://example.com?query and http://example.com/?query are equal:

[...] since the http scheme uses an authorization component, has a default port of 80, and defines an empty path 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 general syntax for privileges with an empty path should be normalized along the path to "/".

0
source

Source: https://habr.com/ru/post/1303282/


All Articles