views:

30

answers:

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)

A: 
FosterZ
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
+1  A: 

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
Thanks for your reply. This to me seems counter-intuitive. Querystring **values** should not be auto-decoded.
Arnold Zokas
@Arnold There is RawUrl property that you can use if you need to and is not decoded.
Aliostad
@Aliostad RawUrl is relative, but it led me to the right solution. I've marked your answer as accepted.
Arnold Zokas