Uri构造函数(new Uri(Uri,String))在两个不同项目中的不同行为

时间:2013-12-19 01:54:15

标签: c# .net

我有两个不同的项目都使用一段共同的代码。一个是Azure云服务网站,另一个是Windows服务。他们都称之为

的功能
private static Uri ConstructUriFromUriAndString(
        Uri endpoint,
        string path)
    {
        // This is where we encode the url path to be valid
        string encodedPath = HttpUtility.UrlEncode(path);
        return new Uri(endpoint, encodedPath);
    }

当我使用uri和编码字符串" images%2fblabla.html"从Windows服务调用此函数时然后Uri的AbsoluteUri属性是" uri / images / blabla.html",我认为这是预期的行为。

当我从Azure站点使用相同的Uri和相同的编码字符串调用此函数时,AbsoluteUri属性为&#34; uri / images&amp; 2fblabla.html&#34;,我后来的http请求正在阻塞。< / p>

我已经使用了&#34;转到定义&#34;在这两种情况下,两者都解析为System.dll版本2.0.0.0。 Windows服务使用.NET 4,Azure站点使用.NET 4.5。我不认为这是一个问题,因为它们都使用相同的System.dll程序集。

如何使用相同的参数调用相同的函数并获得不同的结果?

1 个答案:

答案 0 :(得分:1)

这显然是一个已知问题,是由.NET 4-4.5差异引起的。

另见 -

System.Net.Uri with urlencoded characters

Accessing private members from powershell