为什么 URI 构造函数从 baseUri 参数中删除部分路径?
Why does the URI constructor remove part of path from the baseUri argument?
public class Program
{
public static void Main()
{
Uri baseUri = new Uri("http://localhost:7777/BasePath/");
Uri uri = new Uri(baseUri, "/controller");
Console.WriteLine(uri);
}
}
从 uri 中擦除 /BasePath 是否是预期的行为,最终结果是 http://localhost:7777/controller
?
我不得不深入研究 documentation for the constructor you're calling。
public Uri (Uri baseUri, string relativeUri);
Additionally, if the relativeUri
begins with a slash, then it will replace any relative part of the baseUri
.
这是预期的行为。如果指定以斜杠开头的相对路径,它会假定相对路径是 整个 相对路径,因此它会丢弃任何已包含在 baseUri
中的相对路径。
public class Program
{
public static void Main()
{
Uri baseUri = new Uri("http://localhost:7777/BasePath/");
Uri uri = new Uri(baseUri, "/controller");
Console.WriteLine(uri);
}
}
从 uri 中擦除 /BasePath 是否是预期的行为,最终结果是 http://localhost:7777/controller
?
我不得不深入研究 documentation for the constructor you're calling。
public Uri (Uri baseUri, string relativeUri);
Additionally, if the
relativeUri
begins with a slash, then it will replace any relative part of thebaseUri
.
这是预期的行为。如果指定以斜杠开头的相对路径,它会假定相对路径是 整个 相对路径,因此它会丢弃任何已包含在 baseUri
中的相对路径。