I recently detected, that UrlHelper.IsLocalUrl
method always returns false
, if it detects non-ASCII characters in the url
parameter.
Example:
var isLocal = UrlHelper.IsLocalUrl("контакты"); //false
Is it a bug, or "by design"?
I recently detected, that UrlHelper.IsLocalUrl
method always returns false
, if it detects non-ASCII characters in the url
parameter.
Example:
var isLocal = UrlHelper.IsLocalUrl("контакты"); //false
Is it a bug, or "by design"?
The latest available implementation is checking for those conditions:
"/"
and is not followed by "/"
or "\"
"~"
and is followed by "/"
Thus all the urls passed to this method must start with "/"
or "~/"
.
Also, in case you wonder, it doesn't take the current host into account and check for schemes like http
for instance.
Update:
Here is a link to the implementation which is used by UrlHelper.IsLocalUrl
http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/600963a4df15#src/System.Web.WebPages/RequestExtensions.cs
Maybe because the URL in RFC is defined by the US-ASCII code set, with reserved characters.
You can read about URL specification here: http://www.ietf.org/rfc/rfc1738.txt
And a quote from the above site/document:
URLs are written only with the graphic printable characters of the US-ASCII coded character set. The octets 80-FF hexadecimal are not used in US-ASCII, and the octets 00-1F and 7F hexadecimal represent control characters; these must be encoded.
So in short, my guess is "by design".
Note: RFC is set by the IETF, which sets the standards of some technologies such as URL.