2

We have an existing CMS implementation, episerver 7.1, that has a .NET 4.0 app pool and is built against .NET 4.0.

This CMS is forms based and request authentication has been disabled for it. We have a custom page type that has an URL property, and we sometimes use a custom URI scheme in this URL property to dynamically look up catalog links in the code behind, mpc://16403 where 16403 us a unique ID for the product that is not market specific. [This allows the client to add the links once, and then the system looks up the correct market specific link]

We encountered an issue with a service on the machine and had to install .NET 4.5. Suddenly we noticed that the custom links were being corrupted, changing mpc://16403 to mpc://0.0.64.19/

For some reason, after the installation of .NET 4.5, our custom URL is being converted to an IP address. None of the configuration has changed, only the installation of .NET 4.5.

Does anyone know why this is happening and how we can stop it from happening?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
graney
  • 1,365
  • 2
  • 13
  • 20

2 Answers2

3

I would bet that under the covers, System.Uri is being used. If you look through the class reference, you will see that the class parses the string that is passed in to break it into its component parts (scheme, host, etc). In this case, it looks like the parsing logic was modified to assume that a hostname that consists of numbers is an IP address. As far as how to best handle this problem, it looks like you may want to either use strings (probably a bad idea) or a custom protocol handler.

Community
  • 1
  • 1
Bobby D
  • 2,129
  • 14
  • 21
  • I found [IPAddress.Parse Method](http://msdn.microsoft.com/en-us/library/system.net.ipaddress.parse(v=vs.100).aspx) I am guessing [System.Uri](http://msdn.microsoft.com/en-us/library/system.uri.aspx) delegates the interpretation of the _host_ to this. Mostly because the IP address generated is the same. But how would registering a custom protocol handler get System.URI to not transform the `host` into an IP address? – graney Mar 18 '14 at 14:38
  • 1
    I don't think it would.. it's a tough problem.. You may want to double-check the code, when I run this in LinqPad, I get the expected result: `var myUri = new Uri("mpc://16403"); Console.WriteLine(myUri.ToString());` Also, I would read over [this](http://msdn.microsoft.com/en-us/library/hh367887.aspx).. it outlines the framework changes your referenced.. – Bobby D Mar 18 '14 at 15:18
2

OK, there seems to be a bug in how .NET 4.5 handles the System.Uri class.

Specifically it always applies IPAddress.Parse to the host, even if the scheme is unknown. This is wrong as not all 'hosts' are IP addresses.

The following code snippet produces mpc 00.00.64.19 in .NET 4.5 but in .NET 4.0 and .NET 4.5.1 it produces the correct mpc 16403

System.Uri myUri = new System.Uri("mpc://16403"); 
Console.WriteLine(myUri.Scheme + " " + myUri.Host);

So, if you want to use custom schemes with any class/feature derived from System.Uri do not use .NET 4.5 and go straight to .NET 4.5.1

graney
  • 1,365
  • 2
  • 13
  • 20