2

Given url /Page.aspx?a=b&title=apples+%26+pears, Request.Url property returns /Page.aspx?a=b&title=apples+&+pears

Note that the url-encoded ampersand in the second key-value pair has been automatically decoded. Other url-encoded reserved characters aren't being automatically decoded.

Is this behaviour correct?

EDIT: The issue is that Request.Url property is automatically decoding the encoded ampersand when I don't expect it to.

ANSWER: string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Host, Sitecore.Context.Request.RawUrl)

Arnold Zokas
  • 8,306
  • 6
  • 50
  • 76

2 Answers2

2

Reserved characters URLs use some characters for special use in defining their syntax. When these characters are not used in their special role inside a URL, they need to be encoded.

 
 Dollar          ("$")
 Ampersand       ("&")
 Plus            ("+")
 Comma           (",")
 Forward slash   ("/")
 Colon           (":")
 Semi-colon      (";")
 Equals          ("=")
 Question mark   ("?")
 'At' symbol     ("@")

UnSafe charracters

Some characters present the possibility of being misunderstood within URLs for various reasons. These characters should also always be encoded.

Percent character ("%")

'Pound' character ("#")

Less Than' symbol ("<") 'Greater Than' symbol (">") Space

So the behaviour of URL encoding is correct..

Community
  • 1
  • 1
FosterZ
  • 3,863
  • 6
  • 38
  • 62
  • The querystring values *are* being encoded. The issue is that Request.Url property is automatically decoding the encoded ampersand when I don't expect it to. – Arnold Zokas Oct 21 '10 at 11:22
2

Url property of the Request gets decoded in an internal method called CollapsePercentUFromStringInternal.

You can see this in the reflector. This I assumed is the default behaviour anyway.

Update

You can use RawUrl property to get hold of the un-decoded URL.

Aliostad
  • 80,612
  • 21
  • 160
  • 208