1

I am struggling with the Uri class in .net, when parsing IRIs.

Consider this IRI:

var iriStr = "http://example.com/base/植物/名=しそ;使用部=葉";

When I create and Uri from this (regardless of the iri parsing setting) I get the following:

var uri = new Uri(iriStr);
Assert.AreEqual(iriStr, uri.ToString()); // this works
Assert.AreEqual(iriStr, uri.AbsoluteUri); // this fails

The actual value uri.AbsolutUri returns is:

http://example.com/base/%E6%A4%8D%E7%89%A9%2F%E5%90%8D%3D%E3%81%97%E3%81%9D%3B%E4%BD%BF%E7%94%A8%E9%83%A8%3D%E8%91%89

It seems that the Uri class works as described in the RFC3986 and not RFC3987 specification (although msdn says something else). I need the Uri#AbsoluteUri to return a correct string prepresentation escaped according to the latter.

Why is this that way? Any way to change this behavior?

Eduard Florinescu
  • 16,747
  • 28
  • 113
  • 179
Tomasz Pluskiewicz
  • 3,622
  • 1
  • 19
  • 42
  • Could be this? "The existing Uri class has been extended in .NET Framework v3.5, 3.0 SP1, and 2.0 SP1 to provide IRI support based on RFC 3987. Current users will not see any change from the .NET Framework 2.0 behavior unless they specifically enable IRI. This ensures application compatibility with prior versions of the .NET Framework." Taken from http://msdn.microsoft.com/en-us/library/system.uri.aspx – Sergio Rosas Aug 08 '12 at 10:29
  • I tried. I do enable the iriParsing setting in app/web.config, but it affects Equals, OriginalString, GetComponents, and IsWellFormedOriginalString as described on that page you refer to. AbsoluteUri doesn't change – Tomasz Pluskiewicz Aug 08 '12 at 19:36

0 Answers0