开发者

Querystring with url-encoded ampersand prematurely decoded within Request.Url

开发者 https://www.devze.com 2023-01-20 23:23 出处:网络
Given url /Page.aspx?a=b&title=apples+%26+pears, Request.Url property returns /Page.aspx?a=b&title=apples+&+pears

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)


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号