tags:

views:

84

answers:

3

Hello there, 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.

+2  A: 

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.

Fredou
+2  A: 

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.

Guffa
A: 

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 "/".

Gumbo